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
/
(?:<span class="SC">(?:(?!<\/span>)(?:[^a-z&]|&[^;]+;))*|(?!^)\G(?:(?!<\/span>)(?:[^a-z&]|&[^;]+;))*)([a-z]+)
/
g
Non-capturing group
(?:<span class="SC">(?:(?!<\/span>)(?:[^a-z&]|&[^;]+;))*|(?!^)\G(?:(?!<\/span>)(?:[^a-z&]|&[^;]+;))*)
1st Alternative
<span class="SC">(?:(?!<\/span>)(?:[^a-z&]|&[^;]+;))*
<span class="SC">
matches the characters <span class="SC"> literally (case sensitive)
Non-capturing group
(?:(?!<\/span>)(?:[^a-z&]|&[^;]+;))*
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
Negative Lookahead
(?!<\/span>)
Assert that the Regex below does not match
< matches the character < with index 6010 (3C16 or 748) literally (case sensitive)
\/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
span>
matches the characters span> literally (case sensitive)
Non-capturing group
(?:[^a-z&]|&[^;]+;)
1st Alternative
[^a-z&]
Match a single character not present in the list below
[^a-z&]
a-z matches a single character in the range between a (index 97) and z (index 122) (case sensitive)
& matches the character & with index 3810 (2616 or 468) literally (case sensitive)
2nd Alternative
&[^;]+;
& matches the character & with index 3810 (2616 or 468) literally (case sensitive)
Match a single character not present in the list below
[^;]
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
; matches the character ; with index 5910 (3B16 or 738) literally (case sensitive)
; matches the character ; with index 5910 (3B16 or 738) literally (case sensitive)
2nd Alternative
(?!^)\G(?:(?!<\/span>)(?:[^a-z&]|&[^;]+;))*
Negative Lookahead
(?!^)
Assert that the Regex below does not match
^ asserts position at start of the string
\G asserts position at the end of the previous match or the start of the string for the first match
Non-capturing group
(?:(?!<\/span>)(?:[^a-z&]|&[^;]+;))*
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
Negative Lookahead
(?!<\/span>)
Assert that the Regex below does not match
< matches the character < with index 6010 (3C16 or 748) literally (case sensitive)
\/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
span>
matches the characters span> literally (case sensitive)
Non-capturing group
(?:[^a-z&]|&[^;]+;)
1st Alternative
[^a-z&]
Match a single character not present in the list below
[^a-z&]
a-z matches a single character in the range between a (index 97) and z (index 122) (case sensitive)
& matches the character & with index 3810 (2616 or 468) literally (case sensitive)
2nd Alternative
&[^;]+;
& matches the character & with index 3810 (2616 or 468) literally (case sensitive)
Match a single character not present in the list below
[^;]
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
; matches the character ; with index 5910 (3B16 or 738) literally (case sensitive)
; matches the character ; with index 5910 (3B16 or 738) literally (case sensitive)
1st Capturing Group
([a-z]+)
Match a single character present in the list below
[a-z]
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
a-z matches a single character in the range between a (index 97) and z (index 122) (case sensitive)
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