regex flags for triggers

Posted by Zimmy on Wed 26 Feb 2020 07:03 PM — 3 posts, 14,572 views.

#0
Is there a way to add flags to trigger matches?

I'd like to be able to enable the 'J' flag so I can use duplicate capture groups.

So I can do stuff like this:


/^(?(?=this)(?<this>\w+)( and (?<that>\w+))?|(?<that>\w+))$/gmJ

https://regex101.com/r/Hh0hTN/4


[EDIT]I attempted to compile the match text with rex.new() using the DUPNAMES flag and then using SetTriggerOption() to set the match of the trigger with the complied regex. It didn't work because the regex is considered userdata and it wanted a string.
Amended on Wed 26 Feb 2020 07:28 PM by Zimmy
Australia Forum Administrator #1
See: http://www.gammon.com.au/regexp and scroll down to "Duplicate names".

Namely:




If you are using named patterns you can now have the same name multiple times, provided you put the "(?J)" option in your pattern. For example:



Match: (?J)(?P<name>Ni.+)|(?P<name>Fr.+)



This would match "Nick" or "Fred", and whichever one matched, the named pattern "name" would be set to it.
#2
Very cool, thanks!