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
/
^ (?:[ab]+b) ? (?:aa)* a $
/
gmx
^ asserts position at start of a line
Non-capturing group
(?:[ab]+b) ?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
Match a single character present in the list below
[ab]
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
ab
matches a single character in the list ab (case sensitive)
b matches the character b with index 9810 (6216 or 1428) literally (case sensitive)
Non-capturing group
(?:aa)*
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
aa
matches the characters aa literally (case sensitive)
a
matches the character a with index 3210 (2016 or 408) literally (case sensitive)
$ asserts position at the end of a line
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)
x modifier: extended. Spaces and text after a # in the pattern are ignored
Your regular expression does not match the subject string.Try launching the debugger to find out why.

Regular Expression
No Match

/
/
gmx

Test String