Regular Expressions 101

Save & Share

  • Save Regex
    ctrl+s
  • Update Regex
    ctrl+⇧+s

Flavor

  • PCRE2 (PHP >=7.3)
  • PCRE (PHP <7.3)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java 8

Function

  • Match
  • Substitution
  • List
  • Unit Tests
/
(?:\G(?!\A)|\[)[^]\s]*\K\s+
/
g
Non-capturing group
(?:\G(?!\A)|\[)
1st Alternative
\G(?!\A)
\G asserts position at the end of the previous match or the start of the string for the first match
Negative Lookahead
(?!\A)
Assert that the Regex below does not match
\A asserts position at start of the string
2nd Alternative
\[
\[ matches the character [ with index 9110 (5B16 or 1338) literally (case sensitive)
Match a single character not present in the list below
[^]\s]
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
] matches the character ] with index 9310 (5D16 or 1358) literally (case sensitive)
\s matches any whitespace character (equivalent to [\r\n\t\f\v ])
\K resets the starting point of the reported match. Any previously consumed characters are no longer included in the final match
\s
matches any whitespace character (equivalent to [\r\n\t\f\v ])
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
Global pattern flags
g modifier: global. All matches (don't return after first match)
Your regular expression does not match the subject string.Try launching the debugger to find out why.

Regular Expression
No Match

/
/
g

Test String

Substitution

Processing...