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.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ General ➜ Aliases Containing Regex Patterns?

Aliases Containing Regex Patterns?

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


Posted by Nazdravanix   New Zealand  (2 posts)  Bio
Date Tue 13 Jan 2015 01:20 AM (UTC)
Message
Mushclient v 4.96 win7 Lua Scripting

So I have been hacking away at this in a rather primitive manner when it occurred to me I may be creating a bit of an xy problem. Hopefully someone can help me out.

On the mud I play (Discworld) I have a spell that when cast on an item takes you to a location "remembered" by that item. Currently I have 3 aliases for this as I have three different groups of items that need to be manipulated in different ways before the spell is cast (removed from containers etc).

What I want to do is have one master alias that depending on what the matched pattern is behaves in three different ways. I have three group of items. One is nicknamed internally within the mud as three letter codes (eg "rts" or "stl"), the second set is likewise nicknamed but with 3 digit numbers (eg "234" "456" "098"), and the third are just items that I type the full name of (eg "dagger scabbard" "hauberk" "cane").

Each set needs a different set of actions so I tried the following test alias.


<aliases>
  <alias
   name="TestPort"
   match="^test (.*)$"
   enabled="y"
   expand_variables="y"
   group="Testing"
   regexp="y"
   send_to="12"
   ignore_case="y"
   keep_evaluating="y"
   sequence="100"
  >
  <send>if "%1" == "(^[a-z]{3}$)" then
  print ("paper")

elseif "%1" == "(^[0-9]{3}$)"
  print ("rock")

else
  print ("scissors")

end -- if

-- test multi function alias</send>
  </alias>
</aliases>



'test abc' should print "paper"
'test 123' should print "rock"
'test anything else' should print "scissors"

I have tried changing my regex patterns, I have tried multiple brackets and quote locations still can't seem to get it to work. Ive only been trying out this more advanced stuff for a couple of days but I still am a bit down on myself for not being able to nut this out. Can someone put me out of my misery.
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #1 on Tue 13 Jan 2015 02:03 AM (UTC)
Message

if "%1" == "(^[a-z]{3}$)" then


An "if" statement does not evaluate regular expressions.

You want something like:


if string.match ("%1", "(^[a-z]{3}$)") then


Even then, Lua regexps do not work with {3}, so you really want something more like:



if string.match ("%1", "^%%a%%a%%a$") then


I doubled the % symbols because of the way they are processed inside a "send to script" box.

http://www.gammon.com.au/scripts/doc.php?lua=string.find

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nazdravanix   New Zealand  (2 posts)  Bio
Date Reply #2 on Tue 13 Jan 2015 03:11 AM (UTC)
Message
Thanks Nick. Might look into some Lua tutorials so I can avoid simple mistakes like this again.
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.


13,588 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.