Multiline Trigger Regexp Question

Posted by Twrx on Sun 31 Oct 2004 04:35 AM — 2 posts, 11,414 views.

#0
I need help to catch the following Text in Multiline Trigger:


You are carrying: a Torch, a Torch, a Bag, a Magic Potion,
a Rope, 243 Gems, 21 Kristals.


I want to catch all begining with You are carrying,
till the finishing Dot is reached.


Australia Forum Administrator #1
I presume that was just an example?

The trigger below will match that general case, starting with "You are carrying: " and ending with a period. The trailing \Z forces it to match the last one found (in case there are two in recent output).

This one matches anything over 10 lines, however change the 10 below to some other figure as required.


<triggers>
  <trigger
   enabled="y"
   lines_to_match="10"
   match="^You are carrying: (.+)\.$\Z"
   multi_line="y"
   regexp="y"
   send_to="2"
   sequence="100"
  >
  <send>Match: %1</send>
  </trigger>
</triggers>



As shown the trigger just echoes what it matches in the output window. You would need to write a bit of scripting to break up the inventory items.

Search this forum for "split" but basically you need to split up the wildcard at the commas. This is what you see on your example line:


Match: a Torch, a Torch, a Bag, a Magic Potion,a Rope, 243 Gems, 21 Kristals


Now if you do a "split" on that you will get an array of items, for example in this improved version:


<triggers>
  <trigger
   enabled="y"
   lines_to_match="10"
   match="^You are carrying: (.+)\.$\Z"
   multi_line="y"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>inventory = split ("%1", ",")
for each i in inventory 
  world.Note "Item = " &amp; Trim (i)
next
</send>
  </trigger>
</triggers>



This echoes:


Item = a Torch
Item = a Torch
Item = a Bag
Item = a Magic Potion
Item = a Rope
Item = 243 Gems
Item = 21 Kristals


That should be enough for you to do something with.