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
/
((?:(?(?=(e.g.|z.b.|Figs?\.|\d+\.\d))\2|[^.!?])+[.!?]))
/
gi
1st Capturing Group
((?:(?(?=(e.g.|z.b.|Figs?\.|\d+\.\d))\2|[^.!?])+[.!?]))
Non-capturing group
(?:(?(?=(e.g.|z.b.|Figs?\.|\d+\.\d))\2|[^.!?])+[.!?])
Conditional
(?(?=(e.g.|z.b.|Figs?\.|\d+\.\d))\2|[^.!?])+
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
Conditionally matches one of two options depending on whether the lookaround matches
Positive Lookahead
(?=(e.g.|z.b.|Figs?\.|\d+\.\d))
Assert that the Regex below matches
2nd Capturing Group
(e.g.|z.b.|Figs?\.|\d+\.\d)
1st Alternative
e.g.
e matches the character e with index 10110 (6516 or 1458) literally (case insensitive)
. matches any character (except for line terminators)
g matches the character g with index 10310 (6716 or 1478) literally (case insensitive)
. matches any character (except for line terminators)
2nd Alternative
z.b.
z matches the character z with index 12210 (7A16 or 1728) literally (case insensitive)
. matches any character (except for line terminators)
b matches the character b with index 9810 (6216 or 1428) literally (case insensitive)
. matches any character (except for line terminators)
3rd Alternative
Figs?\.
Fig
matches the characters Fig literally (case insensitive)
s
matches the character s with index 11510 (7316 or 1638) literally (case insensitive)
\. matches the character . with index 4610 (2E16 or 568) literally (case insensitive)
4th Alternative
\d+\.\d
\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 4610 (2E16 or 568) literally (case insensitive)
\d matches a digit (equivalent to [0-9])
If condition is met, match the following regex
\2
\2 matches the same text as most recently matched by the 2nd capturing group
Else match the following regex
[^.!?]
Match a single character not present in the list below
[^.!?]
.!?
matches a single character in the list .!? (case insensitive)
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)
i modifier: insensitive. Case insensitive match (ignores case of [a-zA-Z])
Your regular expression does not match the subject string.Try launching the debugger to find out why.

Regular Expression
No Match

/
/
gi

Test String

Regex Debugger

Please wait while your expression is being debugged...