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.
 Entire forum ➜ MUSHclient ➜ Lua ➜ Escape Characters in trigger script

Escape Characters in trigger script

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


Posted by Rene   (46 posts)  Bio
Date Tue 23 Jul 2019 07:51 PM (UTC)

Amended on Tue 23 Jul 2019 07:52 PM (UTC) by Rene

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

Posted by Nick Gammon   Australia  (23,120 posts)  Bio   Forum Administrator
Date Reply #1 on Tue 23 Jul 2019 08:52 PM (UTC)
Message
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, "%%-", "%%%%-")

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


8,064 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.