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
"
(droits? d['\s]?entr\w*)[^,]{0,15}?(?P<g1>\d+[., ]?k?\d{0,3}) ?(|eur\w*)(?!.{0,10}?fai)
"
gmi
1st Capturing Group
(droits? d['\s]?entr\w*)
droit
matches the characters droit literally (case insensitive)
s
matches the character s with index 11510 (7316 or 1638) literally (case insensitive)
d
matches the characters d literally (case insensitive)
Match a single character present in the list below
['\s]
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
' matches the character ' with index 3910 (2716 or 478) literally (case insensitive)
\s matches any whitespace character (equivalent to [\r\n\t\f\v  ])
entr
matches the characters entr literally (case insensitive)
\w
matches any word character (equivalent to [a-zA-Z0-9_])
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
Match a single character not present in the list below
[^,]
{0,15}? matches the previous token between 0 and 15 times, as few times as possible, expanding as needed (lazy)
, matches the character , with index 4410 (2C16 or 548) literally (case insensitive)
Named Capture Group g1
(?P<g1>\d+[., ]?k?\d{0,3})
\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 present in the list below
[., ]
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
.,
matches a single character in the list ., (case insensitive)
k
matches the character k with index 10710 (6B16 or 1538) literally (case insensitive)
\d
matches a digit (equivalent to [0-9])
{0,3} matches the previous token between 0 and 3 times, as many times as possible, giving back as needed (greedy)
matches the character with index 3210 (2016 or 408) literally (case insensitive)
3rd Capturing Group
(|eur\w*)
1st Alternative
matches the character with index 836410 (20AC16 or 202548) literally (case insensitive)
2nd Alternative
eur\w*
eur
matches the characters eur literally (case insensitive)
\w
matches any word character (equivalent to [a-zA-Z0-9_])
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
Negative Lookahead
(?!.{0,10}?fai)
Assert that the Regex below does not match
.
matches any character (except for line terminators)
{0,10}? matches the previous token between 0 and 10 times, as few times as possible, expanding as needed (lazy)
fai
matches the characters fai literally (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

r"
"
gmi

Test String