Multiple line triggers

Posted by Norbert on Sun 12 Sep 2004 07:43 AM — 5 posts, 22,416 views.

USA #0
When I test this trigger with trace on, it shows that it matches, it also matches again on each of the next 2 lines that appear in the output window. So the trigger matches an extra 2 times when tested.


<triggers>
  <trigger
   enabled="y"
   lines_to_match="11"
   match="^You are (.*?) \((.*?)\)\,\nPlayer level (.*?)\, barbarian level (.*?)\.\nYou have (.*?) player experience\, (.*?) tribe exp\.\n(.*?)\/(.*?) hit points \((.*?)\/(.*?) spell points\)\, (.*?)\/(.*?) quest points\,\n(.*?) Strength\, (.*?) Dexterity\, (.*?) Constitution\, and (.*?) gold coins\.\nYou have (.*?) experience you can make into (.*?) tribe experience\.\nYou are (.*?)\.\n(?:Wimpy .*?\n|)(?:You are in barbarian weaponless combat mode\.\n|)You are (.*?)\.\nage\: (?: (\d+) day(?:s|)|)(?: (\d+) hour(?:s|)|)(?: (\d+) minute(?:s|)|)(?: (\d+) second(?:s|)|)\.$"
   multi_line="y"
   name="barbtrig"
   regexp="y"
   send_to="10"
   sequence="100"
  >
  <send>/world.note &quot;barb&quot;</send>
  </trigger>
</triggers>




You are Joe the Elder of the Haraku (crusader),
Player level E8, barbarian level 20.
You have 27,858,768 player experience, 1,857,268 tribe exp.
301/301 hit points (69/69 spell points), 408/450 quest points,
22 Strength, 21 Dexterity, 21 Constitution, and 121,954 gold coins.
You have 2,100,707 experience you can make into 105,035 tribe experience.
You are in a drunken stupor.
Wimpy mode.  You should be ashamed.
You are in barbarian weaponless combat mode.
You are somewhat tired.
age:  8 days 7 hours 32 minutes 23 seconds.


I'm not sure if this is a bug or not, but what I was thinking that maybe causing the problem was that 2 of the \n are enclosed in parenthses. Maybe they are hidden from mushclient and muschlient thinks it only got 9 lines when it really got 11 lines. Hence matching on the very next 2 lines. The reason for (?:Wimpy .*?\n|)(?:You are in barbarian weaponless combat mode\.\n|) is because those lines are not always there.
Amended on Sun 12 Sep 2004 02:48 PM by Norbert
Australia Forum Administrator #1
I can't reproduce that. In my test it only matches once. Perhaps paste the "next 2 lines" or whatever makes it match for you.
USA #2
Sorry about that I forgot to change the what it matches on. It does it when the wimpy or combat mode is turned off, so the data it's matching on would look like this below. I'm really not sure it's a bug, the trigger is set to 11 lines to match, but it's not always going to get 11 lines since wimpy and combat mode are not always turned on.



You are Joe the Elder of the Haraku (crusader),
Player level E8, barbarian level 20.
You have 27,858,768 player experience, 1,857,268 tribe exp.
301/301 hit points (69/69 spell points), 408/450 quest points,
22 Strength, 21 Dexterity, 21 Constitution, and 121,954 gold coins.
You have 2,100,707 experience you can make into 105,035 tribe experience.
You are in a drunken stupor.
You are somewhat tired.
age:  8 days 7 hours 32 minutes 23 seconds.
Australia Forum Administrator #3
OK, the solution is simple. It's not a bug. :)

It is correctly detecting that the text you want to match is somewhere in the last 11 lines, even if the text is only 9 lines long.

What you need to do is add \Z to the end, just before the $.

I won't reproduce the whole thing, but it will look like this:


^You are (blah blah) \.\Z$


If you look at the regular expression documentation it says that:


  \Z     matches at end of subject or before newline at end


This is the important thing, "at end of subject". In other words it will only match when your regular expression is at the *end* of the text. So, if extra lines appear, it is no longer at the end, so it doesn't match any more.
USA #4
Thank you very much, that fixed the problem.

I was using the Regular expression syntax link (http://www.gammon.com.au/mushclient/regexp.htm) to help me make the trigger and \Z is not on that page, but I did find it in the mushclient help after I read your post.