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
/
(^|\b)([5,9]\d{2,}|\d{4,})(\.\d+)? (dollar|\$)(\b|\n)
/
gm
1st Capturing Group
(^|\b)
1st Alternative
^
^ asserts position at start of a line
2nd Alternative
\b
\b assert position at a word boundary: (^\w|\w$|\W\w|\w\W)
2nd Capturing Group
([5,9]\d{2,}|\d{4,})
1st Alternative
[5,9]\d{2,}
Match a single character present in the list below
[5,9]
5,9
matches a single character in the list 5,9 (case sensitive)
\d
matches a digit (equivalent to [0-9])
{2,} matches the previous token between 2 and unlimited times, as many times as possible, giving back as needed (greedy)
2nd Alternative
\d{4,}
\d
matches a digit (equivalent to [0-9])
{4,} matches the previous token between 4 and unlimited times, as many times as possible, giving back as needed (greedy)
3rd Capturing Group
(\.\d+)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
\. matches the character . with index 4610 (2E16 or 568) literally (case sensitive)
\d
matches a digit (equivalent to [0-9])
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
matches the character with index 3210 (2016 or 408) literally (case sensitive)
4th Capturing Group
(dollar|\$)
1st Alternative
dollar
dollar
matches the characters dollar literally (case sensitive)
2nd Alternative
\$
\$ matches the character $ with index 3610 (2416 or 448) literally (case sensitive)
5th Capturing Group
(\b|\n)
1st Alternative
\b
\b assert position at a word boundary: (^\w|\w$|\W\w|\w\W)
2nd Alternative
\n
\n matches a line-feed (newline) character (ASCII 10)
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)
Your regular expression does not match the subject string.Try launching the debugger to find out why.

Regular Expression
No Match

/
/
gm

Test String