(?x)applies the following effective flags to the remainder of the pattern: gx x modifier: extended. Ignores unescaped whitespace and comments outside character classes
Comment: Allow comments in regex (ignore whitespace)
Non-Capturing Group(?: # Repeat *
[^(|)]*+ # Match every char except ( ) or |
( # 1. Group 1
\( # Opening paren
(?: # chars inside:
[^()]++ # a. everything inside parens except nested parens
| # or
(?1) # b. nested parens (recurse group 1)
) #
\) # Until closing paren.
)?+ # (end of group 1)
)*+ *+repeats the group contents below any number of times:
Comment: Repeat *
Negated Character Class[^(|)]*+ *+matches any number of characters outside the set below:
(the literal ( (4010 / 508 / 2816)
|the literal | (12410 / 1748 / 7C16)
)the literal ) (4110 / 518 / 2916)
Comment: Match every char except ( ) or |
Group 1( # 1. Group 1
\( # Opening paren
(?: # chars inside:
[^()]++ # a. everything inside parens except nested parens
| # or
(?1) # b. nested parens (recurse group 1)
) #
\) # Until closing paren.
)?+ ?+repeats the group contents below at most once:
Comment: 1. Group 1
\(the literal ( (4010 / 508 / 2816)
Comment: Opening paren
Non-Capturing Group(?: # chars inside:
[^()]++ # a. everything inside parens except nested parens
| # or
(?1) # b. nested parens (recurse group 1)
) 1st Alternative # chars inside:
[^()]++ # a. everything inside parens except nested parens
Comment: chars inside:
Negated Character Class[^()]++ ++matches at least one character outside the set below:
(the literal ( (4010 / 508 / 2816)
)the literal ) (4110 / 518 / 2916)
Comment: a. everything inside parens except nested parens
2nd Alternative # or
(?1) # b. nested parens (recurse group 1)
Comment: or
(?1)calls group 1 as a subroutine
Comment: b. nested parens (recurse group 1)
Comment:
\)the literal ) (4110 / 518 / 2916)
Comment: Until closing paren.
Comment: (end of group 1)
Comment:
\Kresets the starting point of the reported match. Any previously consumed characters are no longer included in the final match
Comment: Keep text out of match
\|the literal | (12410 / 1748 / 7C16)
Comment: Match a pipe
g modifier: global. Finds all matches instead of stopping after the first