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
/
^((sdf|xvd)[a-x][0-9]{0,1})\s+[^\s]+\s+[^\s+]\s+([^\s]+)\s+[^\s]+\s+[^\s]+\s+([^\n]*)$
/
misU
^ asserts position at start of a line
1st Capturing Group
((sdf|xvd)[a-x][0-9]{0,1})
2nd Capturing Group
(sdf|xvd)
1st Alternative
sdf
sdf
matches the characters sdf literally (case insensitive)
2nd Alternative
xvd
xvd
matches the characters xvd literally (case insensitive)
Match a single character present in the list below
[a-x]
a-x matches a single character in the range between a (index 97) and x (index 120) (case insensitive)
Match a single character present in the list below
[0-9]
{0,1} matches the previous token between zero and one times, as few times as possible, expanding as needed (lazy)
0-9 matches a single character in the range between 0 (index 48) and 9 (index 57) (case insensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v ])
+ matches the previous token between one and unlimited times, as few times as possible, expanding as needed (lazy)
Match a single character not present in the list below
[^\s]
+ matches the previous token between one and unlimited times, as few times as possible, expanding as needed (lazy)
\s matches any whitespace character (equivalent to [\r\n\t\f\v ])
\s
matches any whitespace character (equivalent to [\r\n\t\f\v ])
+ matches the previous token between one and unlimited times, as few times as possible, expanding as needed (lazy)
Match a single character not present in the list below
[^\s+]
\s matches any whitespace character (equivalent to [\r\n\t\f\v ])
+ matches the character + with index 4310 (2B16 or 538) literally (case insensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v ])
+ matches the previous token between one and unlimited times, as few times as possible, expanding as needed (lazy)
3rd Capturing Group
([^\s]+)
Match a single character not present in the list below
[^\s]
+ matches the previous token between one and unlimited times, as few times as possible, expanding as needed (lazy)
\s matches any whitespace character (equivalent to [\r\n\t\f\v ])
\s
matches any whitespace character (equivalent to [\r\n\t\f\v ])
+ matches the previous token between one and unlimited times, as few times as possible, expanding as needed (lazy)
Match a single character not present in the list below
[^\s]
+ matches the previous token between one and unlimited times, as few times as possible, expanding as needed (lazy)
\s matches any whitespace character (equivalent to [\r\n\t\f\v ])
\s
matches any whitespace character (equivalent to [\r\n\t\f\v ])
+ matches the previous token between one and unlimited times, as few times as possible, expanding as needed (lazy)
Match a single character not present in the list below
[^\s]
+ matches the previous token between one and unlimited times, as few times as possible, expanding as needed (lazy)
\s matches any whitespace character (equivalent to [\r\n\t\f\v ])
\s
matches any whitespace character (equivalent to [\r\n\t\f\v ])
4th Capturing Group
([^\n]*)
$ asserts position at the end of a line
Global pattern flags
m modifier: multi line. Causes ^ and $ to match the begin/end of each line (not only begin/end of string)
i modifier: insensitive. Case insensitive match (ignores case of [a-zA-Z])
s modifier: single line. Dot matches newline characters
U modifier: Ungreedy. The match becomes lazy by default. Now a ? following a quantifier makes it greedy
Your regular expression does not match the subject string.Try launching the debugger to find out why.

Regular Expression
No Match

/
/
misU

Test String