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
"
\d+(?:st|nd|rd|th)
"
\d
matches a digit (equivalent to [0-9])
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
Non-capturing group
(?:st|nd|rd|th)
1st Alternative
st
st
matches the characters st literally (case sensitive)
2nd Alternative
nd
nd
matches the characters nd literally (case sensitive)
3rd Alternative
rd
rd
matches the characters rd literally (case sensitive)
4th Alternative
th
th
matches the characters th literally (case sensitive)
Your regular expression does not match the subject string.

Regular Expression
No Match

r"
"

Test String