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)
/
^(?!(?*.* (.)+)(?!.*\1))
/
u
^ asserts position at start of the string
Negative Lookahead
(?!(?*.* (.)+)(?!.*\1))
Assert that the Regex below does not match
Non-atomic Positive Lookahead
(?*.* (.)+)
Assert that the Regex below matches
.
matches any character, including unicode (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)
1st Capturing Group
(.)+
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
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
. matches any character, including unicode (except for line terminators)
Negative Lookahead
(?!.*\1)
Assert that the Regex below does not match
.
matches any character, including unicode (except for line terminators)
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
\1 matches the same text as most recently matched by the 1st capturing group
Global pattern flags
u modifier: unicode. Pattern strings are treated as UTF-16. Also causes escape sequences to match unicode characters

Regular Expression

/
/
u

Unit Tests

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