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
"
(droit au bail|DAB)\s?(\W|du|de|fix[] []|[]|est de)? (\d+.\d+|\d+\s\d+)
"
gm
1st Capturing Group
(droit au bail|DAB)
1st Alternative
droit au bail
droit au bail
matches the characters droit au bail literally (case sensitive)
2nd Alternative
DAB
DAB
matches the characters DAB literally (case sensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v  ])
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
2nd Capturing Group
(\W|du|de|fix[] []|[]|est de)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
1st Alternative
\W
\W matches any non-word character (equivalent to [^a-zA-Z0-9_])
2nd Alternative
du
du
matches the characters du literally (case sensitive)
3rd Alternative
de
de
matches the characters de literally (case sensitive)
4th Alternative
fix[] []
fix
matches the characters fix literally (case sensitive)
Match a single character present in the list below
[]
matches a single character in the list (case sensitive)
matches the character with index 3210 (2016 or 408) literally (case sensitive)
Match a single character present in the list below
[]
matches a single character in the list (case sensitive)
5th Alternative
[]
Match a single character present in the list below
[]
matches a single character in the list (case sensitive)
6th Alternative
est de
est de
matches the characters est de literally (case sensitive)
matches the character with index 3210 (2016 or 408) literally (case sensitive)
3rd Capturing Group
(\d+.\d+|\d+\s\d+)
1st 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 any character (except for line terminators)
\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)
2nd Alternative
\d+\s\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)
\s matches any whitespace character (equivalent to [\r\n\t\f\v  ])
\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)
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.

Regular Expression
No Match

r"
"
gm

Test String