Escape Characters in trigger script

Posted by Rene on Tue 23 Jul 2019 07:51 PM — 2 posts, 11,413 views.

#0
Hello,
I noticed that in string.match and string.gsub I need to escape hyphens, i.e. instead of '-' to use '%-' to match a hyphen.
So to replace any hyphens in the matching pattern I used:

match_string = "New-York"
match_string = string.gsub(match_string, "%-", "%%-")
city_match = string.match("I Love New-York", match_string)


This worked fine in a plugin. However I tried doing the same thing from withing MUSH in a trigger (ctrl+shift+8) with Send To as script, and I found that it was not working because it was not escaping the hyphen anymore and even after 'string.gsub' 'match_string' was still "New-York" and not "New%-York" like in the plugin. How can I fix this?
Thanks.
Amended on Tue 23 Jul 2019 07:52 PM by Rene
Australia Forum Administrator #1
In "send to script" you use %something for wildcards (eg. %1 for wildcard 1).

Thus in send-to-script you must double the % symbols if you want a %.

For example:


match_string = string.gsub(match_string, "%%-", "%%%%-")