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 (17)
`
^(('' |^)(('. )*|(.' )*))*$
`
^ asserts position at start of the string
1st Capturing Group
(('' |^)(('. )*|(.' )*))*
* matches the previous token between zero 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
2nd Capturing Group
('' |^)
1st Alternative
''
''
matches the characters '' literally (case sensitive)
2nd Alternative
^
^ asserts position at start of the string
3rd Capturing Group
(('. )*|(.' )*)
1st Alternative
('. )*
4th Capturing Group
('. )*
* matches the previous token between zero 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 the character ' with index 3910 (2716 or 478) literally (case sensitive)
. matches any character (except for line terminators)
matches the character with index 1010 (A16 or 128) literally (case sensitive)
2nd Alternative
(.' )*
5th Capturing Group
(.' )*
* matches the previous token between zero 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 (except for line terminators)
'
matches the characters ' literally (case sensitive)
$ asserts position at the end of the string

Regular Expression

`
`

Unit Tests

given the string x' 'x assert that regex does not match
given the string '' xx '' assert that regex does not match
given the string x' xx 'x assert that regex does not match
given the string '' 'x xx 'x '' assert that regex does not match
given the string x' x' xx '' assert that regex does not match
given the string '' 'x xx x' 'x '' '' assert that regex does not match
given the string x' x' x' '' x' 'x '' 'x '' assert that regex does not match
given the string '' '' '' '' 'x xx x' xx 'x 'x assert that regex does not match
given the string '' assert that regex does match
given the string x' '' assert that regex does match
given the string '' 'x assert that regex does match
given the string '' '' '' assert that regex does match
given the string x' '' 'x assert that regex does match
given the string '' '' x' '' assert that regex does match
given the string '' 'x '' x' '' 'x '' x' '' assert that regex does match
given the string x' x' '' 'x 'x '' '' x' x' '' 'x assert that regex does match
additional unsolvable maze test case