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 ➜ Complex Regex Match Pattern for Trigger

Complex Regex Match Pattern for Trigger

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


Posted by Tharius   (29 posts)  Bio
Date Sun 08 Dec 2013 02:56 PM (UTC)
Message
In a similar vein to the question asked here http://mushclient.com/forum/bbshowpost.php?bbsubject_id=12171
I'm having a hard time with a trigger pattern.

I need a complex pattern since the order of the variables is not guaranteed and in a follow up to my question http://mushclient.com/forum/?id=12312 where I can decode the incoming prompt and create a variable to represent my matching string I created a test case:

Input:
Lareawan (1701/1551h 746/746v |-3|A|S 54,252,377g )

Try a straight regex match of my prompt:
.* \((\d*)/(\d*)h (\d*)/(\d*)v \|.* \)
Works like magic.

Try a specific case:
.* \((@!thCurHp)/(\d*)h (\d*)/(\d*)v \|.* \)
Does not fire.

I thought that perhaps because the variable was not created it might be the problem so I went and created it manually, but no change.

Options: Keep evaluating, Regular expression, Expand variables

Send To: Output (for testing purposes)

So the two questions are, what have I goobered? If the variables do not exist, will they be created by the trigger on first match or what is the defined behaviour?

Thanks all
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #1 on Mon 09 Dec 2013 04:20 AM (UTC)
Message
Can you post the whole thing please?

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.

- Nick Gammon

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

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #2 on Mon 09 Dec 2013 04:21 AM (UTC)
Message
Also since you are using a variable, post the variable contents (in the same way).

- Nick Gammon

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

Posted by Tharius   (29 posts)  Bio
Date Reply #3 on Mon 09 Dec 2013 11:31 AM (UTC)

Amended on Mon 09 Dec 2013 08:50 PM (UTC) by Nick Gammon

Message

<triggers>
  <trigger
   enabled="y"
   expand_variables="y"
   group="ThariPrompt"
   keep_evaluating="y"
   match=".* \((@!thCurHp)/(\d*)h (\d*)/(\d*)v \|.* \)"
   regexp="y"
   send_to="2"
   sequence="101"
  >
  <send>found hp and it is @thCurHp out of thMaxHp</send>
  </trigger>
</triggers>


Note: I know that the second variable in the send needs an @ before it will do anything at all, but I wanted to ensure it wasn't provoking a send failure of some sort.


<variables>
  <variable name="thCurHp">"0"</variable>
</variables>


I have also used a value of 0 without quotes to the same effect.


I think I can remove the regex entirely and go with a more literal match but I'd still like to see if I can answer this in case the technique is helpful elsewhere.

Thanks :)

Code tags added
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #4 on Mon 09 Dec 2013 08:52 PM (UTC)
Message
How is that supposed to work?

It will substitute the value in thCurHp (0) into the regexp giving:


   match=".* \((0)/(\d*)h (\d*)/(\d*)v \|.* \)" 


As your HP are not zero that won't match.

- Nick Gammon

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

Posted by Tharius   (29 posts)  Bio
Date Reply #5 on Tue 10 Dec 2013 01:35 AM (UTC)
Message
Then it seems I have misunderstood the purpose of using this syntax.

In the example I cited he used "^@leader tells you \'(@!customcommand)\'$" ... I understood @!customcommand was a variable that gave the allowed options, but I didn't see him define @leader anywhere so I assumed that it was being filled in as part of the pattern match.

If there's no way to directly achieve that I'll simply build an index variable that will tell what the ordering is.
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #6 on Tue 10 Dec 2013 01:55 AM (UTC)
Message
In this case:

"^@leader tells you \'(@!customcommand)\'$"

The @leader part is replaced by the contents of the variable "leader" and the @!customcommand part is replaced by the variable "customcommand".

That's for matching purposes, it doesn't change those variables afterwards.

Therefore those variables must exist and contain stuff that you want to match on.

- Nick Gammon

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

Posted by Tharius   (29 posts)  Bio
Date Reply #7 on Tue 10 Dec 2013 04:09 AM (UTC)
Message
I understand now, thanks Nick.

I see that I'll have to use (/d*) for the numerics and create an index that relates the %1-%whatever to the various variables.

Thanks for clearing everything up for me.
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.


22,397 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.