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
/
([\W\S]\s[\w\W]{2}.+),\s(.+)\1([!?.])
/
gmi
1st Capturing Group
([\W\S]\s[\w\W]{2}.+)
Match a single character present in the list below
[\W\S]
\W matches any non-word character (equivalent to [^a-zA-Z0-9_])
\S matches any non-whitespace character (equivalent to [^\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
\s matches any whitespace character (equivalent to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
Match a single character present in the list below
[\w\W]
{2} matches the previous token exactly 2 times
\w matches any word character (equivalent to [a-zA-Z0-9_])
\W matches any non-word character (equivalent to [^a-zA-Z0-9_])
.
matches any character (except for line terminators)
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
, matches the character , with index 4410 (2C16 or 548) literally (case insensitive)
\s matches any whitespace character (equivalent to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
2nd Capturing Group
(.+)
.
matches any character (except for line terminators)
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
\1 matches the same text as most recently matched by the 1st capturing group
3rd Capturing Group
([!?.])
Match a single character present in the list below
[!?.]
!?.
matches a single character in the list !?. (case insensitive)
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])
Your regular expression does not match the subject string.

Regular Expression
No Match

/
/
gmi

Test String

Substitution

Processing...