Regular Expressions 101

Save & Share

  • Save Regex
    ctrl+s
  • Update Regex
    ctrl+⇧+s

Flavor

  • PCRE2 (PHP >=7.3)
  • PCRE (PHP <7.3)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java 8

Function

  • Match
  • Substitution
  • List
  • Unit Tests (12)
/
((?=(?=.* (\2?(.?))).*\3.*( \2))){500}.*\4$
/
1st Capturing Group
((?=(?=.* (\2?(.?))).*\3.*( \2))){500}
{500} matches the previous token exactly 500 times
A repeated capturing group will only capture the last iteration. Put a capturing group around the repeated group to capture all iterations or use a non-capturing group instead if you're not interested in the data
Positive Lookahead
(?=(?=.* (\2?(.?))).*\3.*( \2))
Assert that the Regex below matches
Positive Lookahead
(?=.* (\2?(.?)))
Assert that the Regex below matches
.
matches any character (except for line terminators)
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
matches the character with index 1010 (A16 or 128) literally (case sensitive)
2nd Capturing Group
(\2?(.?))
\2
matches the same text as most recently matched by the 2nd capturing group
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
3rd Capturing Group
(.?)
.
matches any character (except for line terminators)
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
.
matches any character (except for line terminators)
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
\3 matches the same text as most recently matched by the 3rd capturing group
.
matches any character (except for line terminators)
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
4th Capturing Group
( \2)
matches the character with index 1010 (A16 or 128) literally (case sensitive)
\2 matches the same text as most recently matched by the 2nd capturing group
.
matches any character (except for line terminators)
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
\4 matches the same text as most recently matched by the 4th capturing group
$ asserts position at the end of the string, or before the line terminator right at the end of the string (if any)

Regular Expression

/
/

Unit Tests

"abcdef", "defbca"
"", ""
"abcdef", "abc"
"😀😁😆", "😁😆😀"
"abcccdee", "decbbbaa"
"abcccdee", "ddd"
"abcdef", ""
"abc", "abc123"
"def", "abcdef"
"", "a"
"abcdef", "bcdefg"
"😀😁😆", "😀😁😆🀀"