Hello, @mark-olson, @ekopalypse and All,
There are a solution with recursive regexes ! Here are 3 kinds of recursive regex which do find paired groups of NON-escaped parentheses !
The regex A looks, from cursor position, for the greatest group of NON-escaped paired parentheses
The regex B looks, from cursor position, for the greatest group of NON-escaped paired parentheses, surrounded by text different from NON-escaped parentheses
The regex C looks, from cursor position, for the greatest range of characters, containing one or several group(s) of NON-escaped paired parentheses, each of them being surrounded by text different from NON-escaped parentheses
Regex A : (?x) (?<!\\) \( (?: (?: \\ [()] | [^()] ) | (?0) )* (?<!\\) \) # Regex A
Regex B : (?x) (?: \\ [()] | [^()] )* ( (?<!\\) \( (?: (?: \\ [()] | [^()] ) | (?1) )* (?<!\\) \) ) (?: \\ [()] | [^()] )* # Regex B
Regex C : (?x) (?: (?: \\ [()] | [^()] )* ( (?<!\\) \( (?: (?: \\ [()] | [^()] ) | (?1) )* (?<!\\) \) ) (?: \\ [()] | [^()] )* )+ # Regex C
Important : Sometimes the regex engine needs to go further on, in order to get a new paired group of parentheses to match !
To test these regexes,:
Paste the text below in a new tab
Put the cursor , on the last line, right before the word This
Run, successively, the regexes A, B and C
C -------------------------------------------------------------------------- -----------------------------------------------------
B ------------------------|------------------------------------------------- -----------------------------------------------------
A -------------- -------------------------------------- ---------------------------------------
x 1 2 1 0 1 2 1 0 x 1 2 1 0
This ( is ( ( a very ) ) small ( test \( to ( verify \( if \) all ) ) these \) ( regexes ( ( match ) NON-escaped \) parentheses) ONLY
In the new tab, you may perfectly spread over your text in many lines without any problem, as shown below :
This
( is (
( a very ) )
small ( tes
t \( to
( verify \(
if
\)
all ) ) these \)
( regexes (
( match ) NON-
escaped \)
parentheses
) ONLY
The regexes will still work ! Just one restriction : You cannot, of course, split an escaped parenthesis in two parts, like below :
these \
) ( regexes
Best Regards,
guy038
P.S. : Of course, if you change the starting position of the search, these recursive regular expressions will certainly find very different results in value and scope !
thanks for the awesome information.