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
/
(?<inverted>!)?\s*(?<name>--?\w[\w-]*)\s*(?<values>(?:\s*(?:\w\S*|["'](?:[^"'\\]*(?:\\.[^"'\\]*)*)['"]))*)\K
/
g
Named Capture Group inverted
(?<inverted>!)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
! matches the character ! with index 3310 (2116 or 418) literally (case sensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v ])
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
Named Capture Group name
(?<name>--?\w[\w-]*)
- matches the character - with index 4510 (2D16 or 558) literally (case sensitive)
-
matches the character - with index 4510 (2D16 or 558) literally (case sensitive)
\w matches any word character (equivalent to [a-zA-Z0-9_])
Match a single character present in the list below
[\w-]
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
\w matches any word character (equivalent to [a-zA-Z0-9_])
- matches the character - with index 4510 (2D16 or 558) literally (case sensitive)
This hyphen is treated literally, which might be confusing for others. Consider escaping it or placing at the start or end of the class!
\s
matches any whitespace character (equivalent to [\r\n\t\f\v ])
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
Named Capture Group values
(?<values>(?:\s*(?:\w\S*|["'](?:[^"'\\]*(?:\\.[^"'\\]*)*)['"]))*)
Non-capturing group
(?:\s*(?:\w\S*|["'](?:[^"'\\]*(?:\\.[^"'\\]*)*)['"]))*
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v ])
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
Non-capturing group
(?:\w\S*|["'](?:[^"'\\]*(?:\\.[^"'\\]*)*)['"])
1st Alternative
\w\S*
\w matches any word character (equivalent to [a-zA-Z0-9_])
\S
matches any non-whitespace character (equivalent to [^\r\n\t\f\v ])
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
2nd Alternative
["'](?:[^"'\\]*(?:\\.[^"'\\]*)*)['"]
Match a single character present in the list below
["']
"'
matches a single character in the list "' (case sensitive)
Non-capturing group
(?:[^"'\\]*(?:\\.[^"'\\]*)*)
Match a single character not present in the list below
[^"'\\]
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
"'
matches a single character in the list "' (case sensitive)
\\ matches the character \ with index 9210 (5C16 or 1348) literally (case sensitive)
Non-capturing group
(?:\\.[^"'\\]*)*
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
\\ matches the character \ with index 9210 (5C16 or 1348) literally (case sensitive)
. matches any character (except for line terminators)
Match a single character not present in the list below
[^"'\\]
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
"'
matches a single character in the list "' (case sensitive)
\\ matches the character \ with index 9210 (5C16 or 1348) literally (case sensitive)
Match a single character present in the list below
['"]
'"
matches a single character in the list '" (case sensitive)
\K resets the starting point of the reported match. Any previously consumed characters are no longer included in the final match
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

Regex Debugger

Please wait while your expression is being debugged...