Regular Expressions 101

Save & Share

Flavor

  • PCRE2 (PHP >=7.3)
  • PCRE (PHP <7.3)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java 8

Function

  • Match
  • Substitution
  • List
  • Unit Tests
/
^(?:подлесок:?+)(?:[ ]*+(?<TS1>[А-Яа-я]{1,4}|\d+)(?=[ ,]|$))?+(?:,?[ ]*+(?<TS2>[А-Яа-я]{1,4}|\d+)(?=[, ]|$))?+(?:,?[ ]*+(?<TS3>[А-Яа-я]{1,4}|\d+)(?=[, ]|$))?+(?:,?[ ]*+(?<TS4>[А-Яа-я]{1,4}|(\d+))(?=[, ]|$))?+(?:,?[ ]*+(?<TS5>[А-Яа-я]{1,4}|\d+)(?=[, ]|$))?+(?:,?[ ]*+(?<DENSITY>средний|густой|редкий|ср\.густ|средней|редкой))?.*+$
/
gmiu
^ asserts position at start of a line
Non-capturing group
(?:подлесок:?+)
подлесок
matches the characters подлесок literally (case insensitive)
:
matches the character : with index 5810 (3A16 or 728) literally (case insensitive)
Non-capturing group
(?:[ ]*+(?<TS1>[А-Яа-я]{1,4}|\d+)(?=[ ,]|$))?+
?+ matches the previous token between zero and one times, as many times as possible, without giving back (possessive)
Match a single character present in the list below
[ ]
*+ matches the previous token between zero and unlimited times, as many times as possible, without giving back (possessive)
matches the character with index 3210 (2016 or 408) literally (case insensitive)
Named Capture Group TS1
(?<TS1>[А-Яа-я]{1,4}|\d+)
1st Alternative
[А-Яа-я]{1,4}
Match a single character present in the list below
[А-Яа-я]
{1,4} matches the previous token between 1 and 4 times, as many times as possible, giving back as needed (greedy)
А-Я matches a single character in the range between А (index 1040) and Я (index 1071) (case insensitive)
а-я matches a single character in the range between а (index 1072) and я (index 1103) (case insensitive)
2nd Alternative
\d+
\d
matches a digit zero through nine in any script except ideographic scripts (equivalent to \p{Nd})
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
Positive Lookahead
(?=[ ,]|$)
Assert that the Regex below matches
1st Alternative
[ ,]
Match a single character present in the list below
[ ,]
,
matches a single character in the list , (case insensitive)
2nd Alternative
$
$ asserts position at the end of a line
Non-capturing group
(?:,?[ ]*+(?<TS2>[А-Яа-я]{1,4}|\d+)(?=[, ]|$))?+
?+ matches the previous token between zero and one times, as many times as possible, without giving back (possessive)
,
matches the character , with index 4410 (2C16 or 548) literally (case insensitive)
Match a single character present in the list below
[ ]
*+ matches the previous token between zero and unlimited times, as many times as possible, without giving back (possessive)
matches the character with index 3210 (2016 or 408) literally (case insensitive)
Named Capture Group TS2
(?<TS2>[А-Яа-я]{1,4}|\d+)
1st Alternative
[А-Яа-я]{1,4}
Match a single character present in the list below
[А-Яа-я]
{1,4} matches the previous token between 1 and 4 times, as many times as possible, giving back as needed (greedy)
А-Я matches a single character in the range between А (index 1040) and Я (index 1071) (case insensitive)
а-я matches a single character in the range between а (index 1072) and я (index 1103) (case insensitive)
2nd Alternative
\d+
\d
matches a digit zero through nine in any script except ideographic scripts (equivalent to \p{Nd})
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
Positive Lookahead
(?=[, ]|$)
Assert that the Regex below matches
1st Alternative
[, ]
Match a single character present in the list below
[, ]
,
matches a single character in the list , (case insensitive)
2nd Alternative
$
$ asserts position at the end of a line
Non-capturing group
(?:,?[ ]*+(?<TS3>[А-Яа-я]{1,4}|\d+)(?=[, ]|$))?+
?+ matches the previous token between zero and one times, as many times as possible, without giving back (possessive)
,
matches the character , with index 4410 (2C16 or 548) literally (case insensitive)
Match a single character present in the list below
[ ]
*+ matches the previous token between zero and unlimited times, as many times as possible, without giving back (possessive)
matches the character with index 3210 (2016 or 408) literally (case insensitive)
Named Capture Group TS3
(?<TS3>[А-Яа-я]{1,4}|\d+)
1st Alternative
[А-Яа-я]{1,4}
Match a single character present in the list below
[А-Яа-я]
{1,4} matches the previous token between 1 and 4 times, as many times as possible, giving back as needed (greedy)
А-Я matches a single character in the range between А (index 1040) and Я (index 1071) (case insensitive)
а-я matches a single character in the range between а (index 1072) and я (index 1103) (case insensitive)
2nd Alternative
\d+
\d
matches a digit zero through nine in any script except ideographic scripts (equivalent to \p{Nd})
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
Positive Lookahead
(?=[, ]|$)
Assert that the Regex below matches
1st Alternative
[, ]
Match a single character present in the list below
[, ]
,
matches a single character in the list , (case insensitive)
2nd Alternative
$
$ asserts position at the end of a line
Non-capturing group
(?:,?[ ]*+(?<TS4>[А-Яа-я]{1,4}|(\d+))(?=[, ]|$))?+
?+ matches the previous token between zero and one times, as many times as possible, without giving back (possessive)
,
matches the character , with index 4410 (2C16 or 548) literally (case insensitive)
Match a single character present in the list below
[ ]
*+ matches the previous token between zero and unlimited times, as many times as possible, without giving back (possessive)
matches the character with index 3210 (2016 or 408) literally (case insensitive)
Named Capture Group TS4
(?<TS4>[А-Яа-я]{1,4}|(\d+))
1st Alternative
[А-Яа-я]{1,4}
Match a single character present in the list below
[А-Яа-я]
{1,4} matches the previous token between 1 and 4 times, as many times as possible, giving back as needed (greedy)
А-Я matches a single character in the range between А (index 1040) and Я (index 1071) (case insensitive)
а-я matches a single character in the range between а (index 1072) and я (index 1103) (case insensitive)
2nd Alternative
(\d+)
5th Capturing Group
(\d+)
\d
matches a digit zero through nine in any script except ideographic scripts (equivalent to \p{Nd})
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
Positive Lookahead
(?=[, ]|$)
Assert that the Regex below matches
1st Alternative
[, ]
Match a single character present in the list below
[, ]
,
matches a single character in the list , (case insensitive)
2nd Alternative
$
$ asserts position at the end of a line
Non-capturing group
(?:,?[ ]*+(?<TS5>[А-Яа-я]{1,4}|\d+)(?=[, ]|$))?+
?+ matches the previous token between zero and one times, as many times as possible, without giving back (possessive)
,
matches the character , with index 4410 (2C16 or 548) literally (case insensitive)
Match a single character present in the list below
[ ]
*+ matches the previous token between zero and unlimited times, as many times as possible, without giving back (possessive)
matches the character with index 3210 (2016 or 408) literally (case insensitive)
Named Capture Group TS5
(?<TS5>[А-Яа-я]{1,4}|\d+)
1st Alternative
[А-Яа-я]{1,4}
Match a single character present in the list below
[А-Яа-я]
{1,4} matches the previous token between 1 and 4 times, as many times as possible, giving back as needed (greedy)
А-Я matches a single character in the range between А (index 1040) and Я (index 1071) (case insensitive)
а-я matches a single character in the range between а (index 1072) and я (index 1103) (case insensitive)
2nd Alternative
\d+
\d
matches a digit zero through nine in any script except ideographic scripts (equivalent to \p{Nd})
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
Positive Lookahead
(?=[, ]|$)
Assert that the Regex below matches
1st Alternative
[, ]
Match a single character present in the list below
[, ]
,
matches a single character in the list , (case insensitive)
2nd Alternative
$
$ asserts position at the end of a line
Non-capturing group
(?:,?[ ]*+(?<DENSITY>средний|густой|редкий|ср\.густ|средней|редкой))?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
,
matches the character , with index 4410 (2C16 or 548) literally (case insensitive)
Match a single character present in the list below
[ ]
*+ matches the previous token between zero and unlimited times, as many times as possible, without giving back (possessive)
matches the character with index 3210 (2016 or 408) literally (case insensitive)
Named Capture Group DENSITY
(?<DENSITY>средний|густой|редкий|ср\.густ|средней|редкой)
1st Alternative
средний
средний
matches the characters средний literally (case insensitive)
2nd Alternative
густой
густой
matches the characters густой literally (case insensitive)
3rd Alternative
редкий
редкий
matches the characters редкий literally (case insensitive)
4th Alternative
ср\.густ
5th Alternative
средней
6th Alternative
редкой
.
matches any character, including unicode (except for line terminators)
*+ matches the previous token between zero and unlimited times, as many times as possible, without giving back (possessive)
$ asserts position at the end of a line
Global pattern flags
g modifier: global. All matches (don't return after first match)
m modifier: multi line. Causes ^ and $ to match the begin/end of each line (not only begin/end of string)
i modifier: insensitive. Case insensitive match (ignores case of [a-zA-Z])
u modifier: unicode. Pattern strings are treated as UTF-16. Also causes escape sequences to match unicode characters
Your regular expression does not match the subject string.Try launching the debugger to find out why.

Regular Expression
No Match

/
/
gmiu

Test String