Regular expression help

Posted by Arundor on Wed 21 Jun 2006 11:15 PM — 3 posts, 12,136 views.

#0
I'm trying to match this line:

You take a drink from * vial.


But only if it is NOT followed by one of these lines:

The potion heals and soothes you.
Ah, the soothing bromides help strengthen your ego.
Your mind feels stronger and more alert.


I'm trying to use this trigger:

<trigger
   enabled="y"
   lines_to_match="2"
   match="(You take a drink from (.*) vial\.\n)(?!((The potion heals and soothes you\.)|(Ah, the soothing bromides help strengthen your ego\.)|(Your mind feels stronger and more alert\.)))"
   multi_line="y"
   regexp="y"
   send_to="2"
   sequence="100"
  >
  <send>Matched.</send>
</trigger>


But it isn't working out. It matches "You take a drink from * vial." no matter what line comes after it. Any suggestions?
Australia Forum Administrator #1
You need to anchor to the start of the subject. Otherwise 2 lines like this cause it to match:


The sun rises.
You take a drink from the blue vial.


That is 2 lines, and after "you take a drink" is NOT the lines you wanted, so it matches. However by anchoring to the start of the subject, you force it to consider "you take a drink" as the start of the two lines.

This worked for me:


<triggers>
  <trigger
   enabled="y"
   lines_to_match="2"
   match="\A(You take a drink from (.*) vial\.\n)(?!((The potion heals and soothes you\.)|(Ah, the soothing bromides help strengthen your ego\.)|(Your mind feels stronger and more alert\.)))"
   multi_line="y"
   regexp="y"
   send_to="2"
   sequence="100"
  >
  <send>Matched.</send>
  </trigger>
</triggers>
#2
Makes sense. Thank you!