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
/
^[ \s\0\x0B]+|[ \s\0\x0B]+$
/
gm
1st Alternative
^[ \s\0\x0B]+
^ asserts position at start of a line
Match a single character present in the list below
[ \s\0\x0B]
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
matches the character with index 3210 (2016 or 408) literally (case sensitive)
\s matches any whitespace character (equivalent to [\r\n\t\f\v ])
\0 matches the character with index 08 (010 or 016) literally (case sensitive)
\x0B matches the character with index B16 (1110 or 138) literally (case sensitive)
2nd Alternative
[ \s\0\x0B]+$
Match a single character present in the list below
[ \s\0\x0B]
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
matches the character with index 3210 (2016 or 408) literally (case sensitive)
\s matches any whitespace character (equivalent to [\r\n\t\f\v ])
\0 matches the character with index 08 (010 or 016) literally (case sensitive)
\x0B matches the character with index B16 (1110 or 138) literally (case sensitive)
$ asserts position at the end of a line
Global pattern flags
g modifier: global. All matches (don't return after first match)
m modifier: multi line. Causes ^ and $ to match the begin/end of each line (not only begin/end of string)
Your regular expression does not match the subject string.Try launching the debugger to find out why.

Regular Expression
No Match

/
/
gm

Test String