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
"
[ \t]+\$[ ]*(?P<in_line>[^$\n]+?)[ \t]*\$[ \t]+
"
mgs
Match a single character present in the list below
[ \t]
+ 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)
\t matches a tab character (ASCII 9)
\$ matches the character $ with index 3610 (2416 or 448) literally (case sensitive)
Match a single character present in the list below
[ ]
* matches the previous token between zero 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)
Named Capture Group in_line
(?P<in_line>[^$\n]+?)
Match a single character not present in the list below
[^$\n]
+? matches the previous token between one and unlimited times, as few times as possible, expanding as needed (lazy)
$ matches the character $ with index 3610 (2416 or 448) literally (case sensitive)
\n matches a line-feed (newline) character (ASCII 10)
Match a single character present in the list below
[ \t]
* matches the previous token between zero 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)
\t matches a tab character (ASCII 9)
\$ matches the character $ with index 3610 (2416 or 448) literally (case sensitive)
Match a single character present in the list below
[ \t]
+ 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)
\t matches a tab character (ASCII 9)
Global pattern flags
m modifier: multi line. Causes ^ and $ to match the begin/end of each line (not only begin/end of string)
g modifier: global. All matches (don't return after first match)
s modifier: single line. Dot matches newline characters
Your regular expression does not match the subject string.

Regular Expression
No Match

r"
"
mgs

Test String