\s*any whitespace character, repeated any number of times
Comment: white spaces
Comment: ######################### KEYS START ##########################
Non-Capturing Group(?: # We\'ll use this to make keys optional
(?P<keys> # named group: keys
\d+ # match digits
| # or
"(?(?=\\\\")..|[^"])*" # match string between "", works even 4 escaped ones "hello \" world"
| # or
\'(?(?=\\\\\')..|[^\'])*\' # match string between \'\', same as above :p
| # or
\$\w+(?:\[(?:[^[\]]|(?R))*\])* # match variables $_POST, $var, $var["foo"], $var["foo"]["bar"], $foo[$bar["fail"]]
) # close group: keys
########################## KEYS END ##########################
\s* # white spaces
=> # match =>
)? ?repeats the group contents below at most once:
Comment: We\'ll use this to make keys optional
Group keys(?P<keys> # named group: keys
\d+ # match digits
| # or
"(?(?=\\\\")..|[^"])*" # match string between "", works even 4 escaped ones "hello \" world"
| # or
\'(?(?=\\\\\')..|[^\'])*\' # match string between \'\', same as above :p
| # or
\$\w+(?:\[(?:[^[\]]|(?R))*\])* # match variables $_POST, $var, $var["foo"], $var["foo"]["bar"], $foo[$bar["fail"]]
) 1st Alternative # named group: keys
\d+ # match digits
Comment: named group: keys
\d+a digit, repeated at least once
Comment: match digits
2nd Alternative # or
"(?(?=\\\\")..|[^"])*" # match string between "", works even 4 escaped ones "hello \" world"
Comment: or
Condition(?(?=\\\\")..|[^"])* *repeats the group contents below any number of times:
Uses the first branch if the lookaround matches
Positive Lookahead(?=\\\\") \\the literal \ (9210 / 1348 / 5C16)
\\the literal \ (9210 / 1348 / 5C16)
"the literal " (3410 / 428 / 2216)
If the condition is true, match this branch:.. .any character
.any character
Otherwise, match this branch:[^"] Negated Character Class[^"] "the literal " (3410 / 428 / 2216)
Comment: match string between "", works even 4 escaped ones "hello \" world"
3rd Alternative # or
\'(?(?=\\\\\')..|[^\'])*\' # match string between \'\', same as above :p
Comment: or
\'the literal ' (3910 / 478 / 2716)
Condition(?(?=\\\\\')..|[^\'])* *repeats the group contents below any number of times:
Uses the first branch if the lookaround matches
Positive Lookahead(?=\\\\\') \\the literal \ (9210 / 1348 / 5C16)
\\the literal \ (9210 / 1348 / 5C16)
\'the literal ' (3910 / 478 / 2716)
If the condition is true, match this branch:.. .any character
.any character
Otherwise, match this branch:[^\'] Negated Character Class[^\'] \'the literal ' (3910 / 478 / 2716)
\'the literal ' (3910 / 478 / 2716)
Comment: match string between \'\', same as above :p
4th Alternative # or
\$\w+(?:\[(?:[^[\]]|(?R))*\])* # match variables $_POST, $var, $var["foo"], $var["foo"]["bar"], $foo[$bar["fail"]]
Comment: or
\$the literal $ (3610 / 448 / 2416)
\w+any word character, repeated at least once
Non-Capturing Group(?:\[(?:[^[\]]|(?R))*\])* *repeats the group contents below any number of times:
\[the literal [ (9110 / 1338 / 5B16)
Non-Capturing Group(?:[^[\]]|(?R))* *repeats the group contents below any number of times:
Negated Character Class[^[\]] [the literal [ (9110 / 1338 / 5B16)
\]the literal ] (9310 / 1358 / 5D16)
(?R)recurses into the entire pattern
\]the literal ] (9310 / 1358 / 5D16)
Comment: match variables $_POST, $var, $var["foo"], $var["foo"]["bar"], $foo[$bar["fail"]]
Comment: close group: keys
Comment: ######################### KEYS END ##########################
\s*any whitespace character, repeated any number of times
Comment: white spaces
Comment: match =>
Comment: make keys optional
\s*any whitespace character, repeated any number of times
Comment: white spaces
Comment: ######################### VALUES START ##########################
Group values(?P<values> # named group: values
\d+ # match digits
| # or
"(?(?=\\\\")..|[^"])*" # match string between "", works even 4 escaped ones "hello \" world"
| # or
\'(?(?=\\\\\')..|[^\'])*\' # match string between \'\', same as above :p
| # or
\$\w+(?:\[(?:[^[\]]|(?R))*\])* # match variables $_POST, $var, $var["foo"], $var["foo"]["bar"], $foo[$bar["fail"]]
| # or
array\s*\((?:[^()]|(?R))*\) # match an array()
| # or
\[(?:[^[\]]|(?R))*\] # match an array, new PHP array syntax: [1, 3, 5] is the same as array(1,3,5)
| # or
(?:function\s+)?\w+\s* # match functions: helloWorld, function name
(?:\((?:[^()]|(?R))*\)) # match function parameters (wut), (), (array(1,2,4))
(?:(?:\s*use\s*\((?:[^()]|(?R))*\)\s*)? # match use(&$var), use($foo, $bar) (optionally)
\{(?:[^{}]|(?R))*\} # match { whatever}
)?;? # match ; (optionally)
) 1st Alternative # named group: values
\d+ # match digits
Comment: named group: values
\d+a digit, repeated at least once
Comment: match digits
2nd Alternative # or
"(?(?=\\\\")..|[^"])*" # match string between "", works even 4 escaped ones "hello \" world"
Comment: or
Condition(?(?=\\\\")..|[^"])* *repeats the group contents below any number of times:
Uses the first branch if the lookaround matches
Positive Lookahead(?=\\\\") If the condition is true, match this branch:.. Otherwise, match this branch:[^"] Comment: match string between "", works even 4 escaped ones "hello \" world"
3rd Alternative # or
\'(?(?=\\\\\')..|[^\'])*\' # match string between \'\', same as above :p
4th Alternative # or
\$\w+(?:\[(?:[^[\]]|(?R))*\])* # match variables $_POST, $var, $var["foo"], $var["foo"]["bar"], $foo[$bar["fail"]]
5th Alternative # or
array\s*\((?:[^()]|(?R))*\) # match an array()
6th Alternative # or
\[(?:[^[\]]|(?R))*\] # match an array, new PHP array syntax: [1, 3, 5] is the same as array(1,3,5)
7th Alternative # or
(?:function\s+)?\w+\s* # match functions: helloWorld, function name
(?:\((?:[^()]|(?R))*\)) # match function parameters (wut), (), (array(1,2,4))
(?:(?:\s*use\s*\((?:[^()]|(?R))*\)\s*)? # match use(&$var), use($foo, $bar) (optionally)
\{(?:[^{}]|(?R))*\} # match { whatever}
)?;? # match ; (optionally)
Comment: close group: values
Comment: ######################### VALUES END ##########################
\s*any whitespace character, repeated any number of times
Comment: white spaces
x modifier: extended. Ignores unescaped whitespace and comments outside character classes
s modifier: single line. Allows a dot to match line terminators
m modifier: multiline. Causes ^ and $ to match the start and end of each line, not only the start and end of the string
g modifier: global. Finds all matches instead of stopping after the first