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
/
^(\/dev\/(sdf|xvd)[a-p][0-9]{0,1})\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)\%\s+([^\n]*)$
/
imsU
^ asserts position at start of a line
1st Capturing Group
(\/dev\/(sdf|xvd)[a-p][0-9]{0,1})
\/ matches the character / with index 4710 (2F16 or 578) literally (case insensitive)
dev
matches the characters dev literally (case insensitive)
\/ matches the character / with index 4710 (2F16 or 578) literally (case insensitive)
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-p]
a-p matches a single character in the range between a (index 97) and p (index 112) (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)
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)
4th 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)
5th 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)
6th 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 ])
\% matches the character % with index 3710 (2516 or 458) 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)
7th Capturing Group
([^\n]*)
Match a single character not present in the list below
[^\n]
* matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
\n matches a line-feed (newline) character (ASCII 10)
$ asserts position at the end of a line
Global pattern flags
i modifier: insensitive. Case insensitive match (ignores case of [a-zA-Z])
m modifier: multi line. Causes ^ and $ to match the begin/end of each line (not only begin/end of string)
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

/
/
imsU

Test String