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
/
((?:\<[^<>]+\>\s?)?)([:]\w+(?!\w*[;]))((?:\s?\<\/[^<>]+\>)?)((?:(?:.(?!\1\2\3))*.){2})\1\2\3
/
1st Capturing Group
((?:\<[^<>]+\>\s?)?)
Non-capturing group
(?:\<[^<>]+\>\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 6010 (3C16 or 748) 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 a single character in the list <> (case sensitive)
\> matches the character > with index 6210 (3E16 or 768) literally (case sensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
2nd Capturing Group
([:]\w+(?!\w*[;]))
Match a single character present in the list below
[:]
: matches the character : with index 5810 (3A16 or 728) literally (case sensitive)
\w
matches any word character (equivalent to [a-zA-Z0-9_])
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
Negative Lookahead
(?!\w*[;])
Assert that the Regex below does not match
\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 present in the list below
[;]
; matches the character ; with index 5910 (3B16 or 738) literally (case sensitive)
3rd Capturing Group
((?:\s?\<\/[^<>]+\>)?)
Non-capturing group
(?:\s?\<\/[^<>]+\>)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
\< matches the character < with index 6010 (3C16 or 748) literally (case sensitive)
\/ matches the character / with index 4710 (2F16 or 578) 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 a single character in the list <> (case sensitive)
\> matches the character > with index 6210 (3E16 or 768) literally (case sensitive)
4th Capturing Group
((?:(?:.(?!\1\2\3))*.){2})
Non-capturing group
(?:(?:.(?!\1\2\3))*.){2}
{2} matches the previous token exactly 2 times
Non-capturing group
(?:.(?!\1\2\3))*
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
. matches any character (except for line terminators)
Negative Lookahead
(?!\1\2\3)
Assert that the Regex below does not match
\1 matches the same text as most recently matched by the 1st capturing group
\2 matches the same text as most recently matched by the 2nd capturing group
\3 matches the same text as most recently matched by the 3rd capturing group
. matches any character (except for line terminators)
\1 matches the same text as most recently matched by the 1st capturing group
\2 matches the same text as most recently matched by the 2nd capturing group
\3 matches the same text as most recently matched by the 3rd capturing group
Your regular expression does not match the subject string.

Regular Expression
No Match

/
/

Test String

Substitution

Processing...