Does AHK Regex support balanced parentheses?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
MarkL
Posts: 11
Joined: 06 Mar 2019, 09:31

Does AHK Regex support balanced parentheses?

Post by MarkL » 06 Oct 2022, 19:14

As per I understand from this SO post, to support Regex balanced parentheses, it must support assign and delete variable on-the-fly such as (?<var>) and (?<-var>)
I see that AHK Regex can remove option on-the-fly such as (?-im), but how about variable?

Is it possible with AHK Regex?

lexikos
Posts: 9592
Joined: 30 Sep 2013, 04:07
Contact:

Re: Does AHK Regex support balanced parentheses?

Post by lexikos » 06 Oct 2022, 19:27

AutoHotkey uses PCRE, which supports subroutines and recursive calls. Subroutines can be used to match balanced parentheses.
This PCRE pattern solves the nested parentheses problem (assume the PCRE_EXTENDED option is set so that white space is ignored):

Code: Select all

  \( ( [^()]++ | (?R) )* \)
https://www.pcre.org/original/doc/html/pcrepattern.html#subpatternsassubroutines

MarkL
Posts: 11
Joined: 06 Mar 2019, 09:31

Re: Does AHK Regex support balanced parentheses?

Post by MarkL » 06 Oct 2022, 19:33

lexikos wrote:
06 Oct 2022, 19:27
AutoHotkey uses PCRE, which supports subroutines and recursive calls. Subroutines can be used to match balanced parentheses.
This PCRE pattern solves the nested parentheses problem (assume the PCRE_EXTENDED option is set so that white space is ignored):

Code: Select all

  \( ( [^()]++ | (?R) )* \)
https://www.pcre.org/original/doc/html/pcrepattern.html#subpatternsassubroutines
Thank you for quick reply!
I'll absolutely check the link today!

Post Reply

Return to “Ask for Help (v1)”