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
/
^(?:export\s+|)(?<key>[[:alnum:]_]+)=((?<quote>["'])?(?<val>.*?[^\\])\k<quote>?|)$
/
mg
^ asserts position at start of a line
Non-capturing group
(?:export\s+|)
1st Alternative
export\s+
export
matches the characters export literally (case sensitive)
\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)
2nd Alternative null, matches any position
Named Capture Group key
(?<key>[[:alnum:]_]+)
Match a single character present in the list below
[[:alnum:]_]
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
[:alnum:] matches a alphanumeric character [a-zA-Z0-9]
_ matches the character _ with index 9510 (5F16 or 1378) literally (case sensitive)
= matches the character = with index 6110 (3D16 or 758) literally (case sensitive)
2nd Capturing Group
((?<quote>["'])?(?<val>.*?[^\\])\k<quote>?|)
1st Alternative
(?<quote>["'])?(?<val>.*?[^\\])\k<quote>?
Named Capture Group quote
(?<quote>["'])?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
Match a single character present in the list below
["']
"'
matches a single character in the list "' (case sensitive)
Named Capture Group val
(?<val>.*?[^\\])
.
matches any character (except for line terminators)
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
Match a single character not present in the list below
[^\\]
\\ matches the character \ with index 9210 (5C16 or 1348) literally (case sensitive)
\k<quote>
matches the same text as most recently matched by the capturing group named quote
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
2nd Alternative null, matches any position
$ 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)
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

/
/
mg

Test String