Definition Group(?(DEFINE) # Start of definitions
(?P<str_double_quotes>
(?<!\\) # Not escaped
" # Match a double quote
(?: # Non-capturing group
[^\\] # Match anything not a backslash
| # Or
\\. # Match a backslash and a single character (ie: an escaped character)
)*? # Repeat the non-capturing group zero or more times, ungreedy/lazy
" # Match the ending double quote
)
(?P<str_single_quotes>
(?<!\\) # Not escaped
' # Match a single quote
(?: # Non-capturing group
[^\\] # Match anything not a backslash
| # Or
\\. # Match a backslash and a single character (ie: an escaped character)
)*? # Repeat the non-capturing group zero or more times, ungreedy/lazy
' # Match the ending single quote
)
(?P<brackets>
\( # Match an opening bracket
(?: # A non capturing group
(?&str_double_quotes) # Recurse/use the str_double_quotes pattern
| # Or
(?&str_single_quotes) # Recurse/use the str_single_quotes pattern
| # Or
[^()] # Anything not a bracket
| # Or
(?&brackets) # Recurse the bracket pattern
)*
\)
)
) Comment: Start of definitions
Group str_double_quotes(?P<str_double_quotes>
(?<!\\) # Not escaped
" # Match a double quote
(?: # Non-capturing group
[^\\] # Match anything not a backslash
| # Or
\\. # Match a backslash and a single character (ie: an escaped character)
)*? # Repeat the non-capturing group zero or more times, ungreedy/lazy
" # Match the ending double quote
) Negative Lookbehind(?<!\\) \\the literal \ (9210 / 1348 / 5C16)
Comment: Not escaped
" the literal text "
Comment: Match a double quote
Non-Capturing Group(?: # Non-capturing group
[^\\] # Match anything not a backslash
| # Or
\\. # Match a backslash and a single character (ie: an escaped character)
)*? *?repeats the group contents below any number of times:
1st Alternative # Non-capturing group
[^\\] # Match anything not a backslash
Comment: Non-capturing group
Negated Character Class[^\\] \\the literal \ (9210 / 1348 / 5C16)
Comment: Match anything not a backslash
2nd Alternative # Or
\\. # Match a backslash and a single character (ie: an escaped character)
Comment: Or
\\the literal \ (9210 / 1348 / 5C16)
.any character
Comment: Match a backslash and a single character (ie: an escaped character)
Comment: Repeat the non-capturing group zero or more times, ungreedy/lazy
" the literal text "
Comment: Match the ending double quote
Group str_single_quotes(?P<str_single_quotes>
(?<!\\) # Not escaped
' # Match a single quote
(?: # Non-capturing group
[^\\] # Match anything not a backslash
| # Or
\\. # Match a backslash and a single character (ie: an escaped character)
)*? # Repeat the non-capturing group zero or more times, ungreedy/lazy
' # Match the ending single quote
) Negative Lookbehind(?<!\\) \\the literal \ (9210 / 1348 / 5C16)
Comment: Not escaped
' the literal text '
Comment: Match a single quote
Non-Capturing Group(?: # Non-capturing group
[^\\] # Match anything not a backslash
| # Or
\\. # Match a backslash and a single character (ie: an escaped character)
)*? *?repeats the group contents below any number of times:
1st Alternative # Non-capturing group
[^\\] # Match anything not a backslash
Comment: Non-capturing group
Negated Character Class[^\\] \\the literal \ (9210 / 1348 / 5C16)
Comment: Match anything not a backslash
2nd Alternative # Or
\\. # Match a backslash and a single character (ie: an escaped character)
Comment: Or
\\the literal \ (9210 / 1348 / 5C16)
.any character
Comment: Match a backslash and a single character (ie: an escaped character)
Comment: Repeat the non-capturing group zero or more times, ungreedy/lazy
' the literal text '
Comment: Match the ending single quote
Group brackets(?P<brackets>
\( # Match an opening bracket
(?: # A non capturing group
(?&str_double_quotes) # Recurse/use the str_double_quotes pattern
| # Or
(?&str_single_quotes) # Recurse/use the str_single_quotes pattern
| # Or
[^()] # Anything not a bracket
| # Or
(?&brackets) # Recurse the bracket pattern
)*
\)
) \(the literal ( (4010 / 508 / 2816)
Comment: Match an opening bracket
Non-Capturing Group(?: # A non capturing group
(?&str_double_quotes) # Recurse/use the str_double_quotes pattern
| # Or
(?&str_single_quotes) # Recurse/use the str_single_quotes pattern
| # Or
[^()] # Anything not a bracket
| # Or
(?&brackets) # Recurse the bracket pattern
)* *repeats the group contents below any number of times:
1st Alternative # A non capturing group
(?&str_double_quotes) # Recurse/use the str_double_quotes pattern
Comment: A non capturing group
(?&str_double_quotes)calls group str_double_quotes as a subroutine
Comment: Recurse/use the str_double_quotes pattern
2nd Alternative # Or
(?&str_single_quotes) # Recurse/use the str_single_quotes pattern
Comment: Or
(?&str_single_quotes)calls group str_single_quotes as a subroutine
Comment: Recurse/use the str_single_quotes pattern
3rd Alternative # Or
[^()] # Anything not a bracket
Comment: Or
Negated Character Class[^()] (the literal ( (4010 / 508 / 2816)
)the literal ) (4110 / 518 / 2916)
Comment: Anything not a bracket
4th Alternative # Or
(?&brackets) # Recurse the bracket pattern
Comment: Or
(?&brackets)calls group brackets as a subroutine
Comment: Recurse the bracket pattern
\)the literal ) (4110 / 518 / 2916)
Comment: End of definitions
Comment: Let's start matching for real now:
n?optionally matches the literal n (11010 / 1568 / 6E16) (case sensitive)
Comment: Match _ or _n
\s*any whitespace character, repeated any number of times
Comment: Optional white spaces
Group results(?P<results>(?&brackets)) (?&brackets)calls group brackets as a subroutine
Comment: Recurse/use the brackets pattern and put it in the results group
s modifier: single line. Allows a dot to match line terminators
x modifier: extended. Ignores unescaped whitespace and comments outside character classes
g modifier: global. Finds all matches instead of stopping after the first