[Home] [Downloads] [Search] [Help/forum]

Gammon Software Solutions forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  rex:match pattern works in immediate window but not in a send to script trigger?

Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?
(New message)
Subject: rex:match pattern works in immediate window but not in a send to script trigger?
Name:
Your forum user name.
Register forum user name
Password:
Your forum password.
Forgotten password?
Message:
Message to be posted (in English, please)
Maximum of 6000 characters. Text only please, no HTML.
Forum codes:
Check this if your message uses 'forum codes' or templates (auto-detected for new posts).
Forum codes Templates

Save this message ...


Subject review (reverse sequence)

Posted by Eupher   (6 posts)  [Biography] bio
Date Wed 11 Aug 2010 01:54 AM (UTC)  quote  ]
Message
Thanks for the help. I'll be sure to post the xml next time. :)
[Go to top] top

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Tue 10 Aug 2010 11:29 PM (UTC)  quote  ]
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
[Go to top] top

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Tue 10 Aug 2010 11:27 PM (UTC)  quote  ]

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.

Template:copying 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: &quot;do (?&lt;order&gt;.+)&quot;$"
   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("%&lt;order&gt;")
print("%&lt;order&gt;")
print(s,e,t)

</send>
  </trigger>
</triggers>



Template:pasting 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: &quot;do (?&lt;order&gt;.+)&quot;$"
   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
[Go to top] top

Posted by Eupher   (6 posts)  [Biography] bio
Date Tue 10 Aug 2010 11:12 PM (UTC)  quote  ]
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 :)
[Go to top] 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.


1,113 views.

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[Home]

Written by Nick Gammon - 5K

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( http://www.gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]