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
/
\b(t)(?:anks *(?=[.?!]\n|to|for|in|ever)|[han]{3}([ks]{2}|x)+|hx|anx)\b
/
gi
\b assert position at a word boundary: (^\w|\w$|\W\w|\w\W)
1st Capturing Group
(t)
t matches the character t with index 11610 (7416 or 1648) literally (case insensitive)
Non-capturing group
(?:anks *(?=[.?!]\n|to|for|in|ever)|[han]{3}([ks]{2}|x)+|hx|anx)
1st Alternative
anks *(?=[.?!]\n|to|for|in|ever)
anks
matches the characters anks literally (case insensitive)
matches the character with index 3210 (2016 or 408) literally (case insensitive)
Positive Lookahead
(?=[.?!]\n|to|for|in|ever)
Assert that the Regex below matches
1st Alternative
[.?!]\n
Match a single character present in the list below
[.?!]
.?!
matches a single character in the list .?! (case insensitive)
\n matches a line-feed (newline) character (ASCII 10)
2nd Alternative
to
to
matches the characters to literally (case insensitive)
3rd Alternative
for
for
matches the characters for literally (case insensitive)
4th Alternative
in
in
matches the characters in literally (case insensitive)
5th Alternative
ever
ever
matches the characters ever literally (case insensitive)
2nd Alternative
[han]{3}([ks]{2}|x)+
Match a single character present in the list below
[han]
{3} matches the previous token exactly 3 times
han
matches a single character in the list han (case insensitive)
2nd Capturing Group
([ks]{2}|x)+
+ 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
1st Alternative
[ks]{2}
Match a single character present in the list below
[ks]
{2} matches the previous token exactly 2 times
ks
matches a single character in the list ks (case insensitive)
2nd Alternative
x
x matches the character x with index 12010 (7816 or 1708) literally (case insensitive)
3rd Alternative
hx
hx
matches the characters hx literally (case insensitive)
4th Alternative
anx
anx
matches the characters anx literally (case insensitive)
\b assert position at a word boundary: (^\w|\w$|\W\w|\w\W)
Global pattern flags
g modifier: global. All matches (don't return after first match)
i modifier: insensitive. Case insensitive match (ignores case of [a-zA-Z])
Your regular expression does not match the subject string.

Regular Expression
No Match

/
/
gi

Test String

Substitution

Processing...