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
"
(\d+[^(a-z)]*)(year|yr|month|mon)
"
gi
1st Capturing Group
(\d+[^(a-z)]*)
\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)
Match a single character not present in the list below
[^(a-z)]
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
( matches the character ( with index 4010 (2816 or 508) literally (case insensitive)
a-z matches a single character in the range between a (index 97) and z (index 122) (case insensitive)
) matches the character ) with index 4110 (2916 or 518) literally (case insensitive)
2nd Capturing Group
(year|yr|month|mon)
1st Alternative
year
year
matches the characters year literally (case insensitive)
2nd Alternative
yr
yr
matches the characters yr literally (case insensitive)
3rd Alternative
month
month
matches the characters month literally (case insensitive)
4th Alternative
mon
mon
matches the characters mon literally (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.

Regular Expression
No Match

r"
"
gi

Test String