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
/
\bvari?((?<=i)a)?((?<=a)b)?((?<=b)l)?((?<=l)e)?\b
/
g
\b assert position at a word boundary: (^\w|\w$|\W\w|\w\W)
var
matches the characters var literally (case sensitive)
i
matches the character i with index 10510 (6916 or 1518) literally (case sensitive)
1st Capturing Group
((?<=i)a)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
Positive Lookbehind
(?<=i)
Assert that the Regex below matches
i matches the character i with index 10510 (6916 or 1518) literally (case sensitive)
a matches the character a with index 9710 (6116 or 1418) literally (case sensitive)
2nd Capturing Group
((?<=a)b)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
Positive Lookbehind
(?<=a)
Assert that the Regex below matches
a matches the character a with index 9710 (6116 or 1418) literally (case sensitive)
b matches the character b with index 9810 (6216 or 1428) literally (case sensitive)
3rd Capturing Group
((?<=b)l)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
Positive Lookbehind
(?<=b)
Assert that the Regex below matches
b matches the character b with index 9810 (6216 or 1428) literally (case sensitive)
l matches the character l with index 10810 (6C16 or 1548) literally (case sensitive)
4th Capturing Group
((?<=l)e)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
Positive Lookbehind
(?<=l)
Assert that the Regex below matches
l matches the character l with index 10810 (6C16 or 1548) literally (case sensitive)
e matches the character e with index 10110 (6516 or 1458) literally (case sensitive)
\b assert position at a word boundary: (^\w|\w$|\W\w|\w\W)
Global pattern flags
g modifier: global. All matches (don't return after first match)
Your regular expression does not match the subject string.Try launching the debugger to find out why.

Regular Expression
No Match

/
/
g

Test String