Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ General ➜ regex flags for triggers

regex flags for triggers

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Zimmy   (31 posts)  Bio
Date Wed 26 Feb 2020 07:03 PM (UTC)

Amended on Wed 26 Feb 2020 07:28 PM (UTC) by Zimmy

Message
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.
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #1 on Wed 26 Feb 2020 08:11 PM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Zimmy   (31 posts)  Bio
Date Reply #2 on Fri 28 Feb 2020 03:43 AM (UTC)
Message
Very cool, thanks!
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


10,345 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.