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
➜ How to use named capture value in triggers
|
How to use named capture value in triggers
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| Zhenzh
China (68 posts) Bio
|
| Date
| Tue 16 Jul 2019 07:26 AM (UTC) |
| Message
| I find there's a way to name value captured from trigger as mentioned in
 |
Regular expressions
- Regular expressions (as used in triggers and aliases) are documented on the Regular expression tips forum page.
- Also see how Lua string matching patterns work, as documented on the Lua string.find page.
|
Regexp: tell (?<who>.+?) (?'what'.+)
Match : tell Nick hi there
Wildcard '1' = 'Nick'
Wildcard '2' = 'hi there'
Wildcard 'who' = 'Nick'
Wildcard 'what' = 'hi there'
The problem is how can I use such named capture in my script.
I used to use script like SetVariable(hp, "%1") to get the first value captured. But it can not work when I tried to use SetVariable(hp, "%hpvalue") to indicate the capture value named by 'hpvalue'. | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #1 on Tue 16 Jul 2019 08:38 PM (UTC) |
| Message
| The help for triggers tells you how to do that. See:
http://www.gammon.com.au/scripts/doc.php?dialog=IDD_EDIT_TRIGGER
Quote:
For named wildcards you can use %<name> (for example, %<mob> for a wildcard with the name "mob"). Named wildcards are produced by using a regular expression and a group like: (?P<mob>.+?)
Also, if you use a script function (not send-to-script) then the wildcards are provided as the 3rd function parameter:
function myTriggerHandler (name, line, wildcards)
print ("Wildcard 'who' is:", wildcards.who)
end -- myTriggerHandler
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | 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.
11,549 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top