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
➜ rex:match pattern works in immediate window but not in a send to script trigger?
rex:match pattern works in immediate window but not in a send to script trigger?
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Eupher
(6 posts) Bio
|
Date
| Tue 10 Aug 2010 11:12 PM (UTC) |
Message
| I'm new to this and probably doing something stupid... but here goes...
I have a trigger in my world file that calls rex:match in the send to script section. The pattern is not matching there, but if I use the same pattern (and test text) in the immediate window then it matches.
Trigger pattern: ^God tells you: "do (?<order>.+)"$
regular expression is checked
send to script is selected
send:
re = rex.new([[^(t|te|tel|tell)\s+(\S+)\s+do\s+(.+)$]])
s,e,t = re:match("%<order>")
print("%<order>")
print(s,e,t)
When I test the trigger, I get the following output:
God tells you: "do tell me do kill"
tell me do kill
nil nil nil
However, if I put the following script into the immediate window:
re = rex.new([[^(t|te|tel|tell)\s+(\S+)\s+do\s+(.+)$]])
s,e,t = re:match("tell me do kill")
print(s,e,t)
I get the following output:
1 15 table: 03B09530
Why is it matching in one place and not the other?
Thanks :) | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #1 on Tue 10 Aug 2010 11:27 PM (UTC) Amended on Tue 10 Aug 2010 11:32 PM (UTC) by Nick Gammon
|
Message
| It would help if you simply pasted the XML from the trigger rather than explaining it piece by piece.
 |
For advice on how to copy aliases, timers or triggers from within MUSHclient, and paste them into a forum message, please see Copying XML.
|
Your problem is that inside the Send box, MUSHclient pre-processes backslash sequences, so that \s won't be sent to the rex.new.
re = rex.new([[^(t|te|tel|tell)\s+(\S+)\s+do\s+(.+)$]])
You need to defeat that by doubling the backslashes, this worked for me:
<triggers>
<trigger
enabled="y"
match="^God tells you: "do (?<order>.+)"$"
regexp="y"
send_to="12"
sequence="110"
>
<send>
re = rex.new([[^(t|te|tel|tell)\\s+(\\S+)\\s+do\\s+(.+)$]])
s,e,t = re:match("%<order>")
print("%<order>")
print(s,e,t)
</send>
</trigger>
</triggers>
 |
For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.
|
If this is confusing, use a script file and put the name of a function in the "Script" box of the trigger, and have the function in your script file. Then you don't need to double the backslashes.
For example:
<triggers>
<trigger
enabled="y"
match="^God tells you: "do (?<order>.+)"$"
regexp="y"
script="mytrigger"
sequence="110"
>
</trigger>
</triggers>
And in your script file:
function mytrigger (name, line, wildcards)
re = rex.new([[^(t|te|tel|tell)\s+(\S+)\s+do\s+(.+)$]])
s,e,t = re:match(wildcards.order)
print(wildcards.order)
print(s,e,t)
-- debugging
require "tprint"
tprint (t)
end -- function mytrigger
Output:
God tells you: "do tell me do kill"
tell me do kill
1 15 table: 03917CC0
1="tell"
2="me"
3="kill"
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #2 on Tue 10 Aug 2010 11:29 PM (UTC) |
Message
| And it would then be more efficient to only "compile" the regexp once:
-- do this when script loaded
re = rex.new([[^(t|te|tel|tell)\s+(\S+)\s+do\s+(.+)$]])
function mytrigger (name, line, wildcards)
s,e,t = re:match(wildcards.order)
print(wildcards.order)
print(s,e,t)
-- debugging
require "tprint"
tprint (t)
end -- function mytrigger
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Eupher
(6 posts) Bio
|
Date
| Reply #3 on Wed 11 Aug 2010 01:54 AM (UTC) |
Message
| Thanks for the help. I'll be sure to post the xml next time. :) | 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.
14,677 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top