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
"
^(.*?)\t(.*?)\t(.*?)\s(m|km|AU)$
"
x
^ asserts position at start of the string
1st Capturing Group
(.*?)
.
matches any character (except for line terminators)
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
\t matches a tab character (ASCII 9)
2nd Capturing Group
(.*?)
.
matches any character (except for line terminators)
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
\t matches a tab character (ASCII 9)
3rd Capturing Group
(.*?)
.
matches any character (except for line terminators)
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
\s matches any whitespace character (equivalent to [\r\n\t\f\v  ])
4th Capturing Group
(m|km|AU)
1st Alternative
m
m matches the character m with index 10910 (6D16 or 1558) literally (case sensitive)
2nd Alternative
km
km
matches the characters km literally (case sensitive)
3rd Alternative
AU
AU
matches the characters AU literally (case sensitive)
$ asserts position at the end of the string, or before the line terminator right at the end of the string (if any)
Global pattern flags
x modifier: extended. Spaces and text after a # in the pattern are ignored
Your regular expression does not match the subject string.

Regular Expression
No Match

r"
"
x

Test String