Complex Regex Match Pattern for Trigger

Posted by Tharius on Sun 08 Dec 2013 02:56 PM — 8 posts, 31,741 views.

#0
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
Australia Forum Administrator #1
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.
Australia Forum Administrator #2
Also since you are using a variable, post the variable contents (in the same way).
#3

<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
Amended on Mon 09 Dec 2013 08:50 PM by Nick Gammon
Australia Forum Administrator #4
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.
#5
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.
Australia Forum Administrator #6
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.
#7
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.