Regular expression question

Posted by Gaem on Tue 18 Sep 2007 10:07 AM — 5 posts, 21,685 views.

#0
I've looked through all the regular expressions posts, but I couldn't see how to do this.

Now, I'd like to match a line, but only if the following line is not something specific. For example.

Someone says "Foo is true"
Someone else says "No it isn't!"

would not match but

Someone says "Foo is true"
(anything apart from "Someone else says "No it isn't!"")

would match.

I'm guessing you have to use a negative lookahead, but I'm not sure how to do it over a new line like that.
USA #1
Well you could use 2 triggers, one for

Someone says "Foo is true"
regexp ^Someone says \"Foo is true\"$

that sets a variable to 1 or true or whatever method you want to check for in the second trigger. Also enables the second trigger, that matches on * or using regexp ^(.*?)$
and the second trigger does an EnableTrigger("name here",false) and checks if %1 (wildcard 1) is whatever you DON'T want it to match on, and if it is returns, else do whatever you want to do.


Another method is to use multi-line trigger as follows...

^Someone says \"Foo is true\"\n(?!Someone else says \"No it isn\'t\!\")$

That will match on any 2 lines that start with
Someone says "Foo is true"
where the second line is NOT
Someone else says "No it isn't!"


Yet another method is having the first line in its own trigger, that in turn sets a variable to a true value, and makes a one shot timer that checks the value of said variable for false. And have another trigger set to the exact line that you DON'T want it to match on, have that set the variable to false, and when the timer fires and checks the variable, if true then it was something else, so have it do its stuff, if false then do nothing.

This last one came to me after having read over my post the 3rd time :)

Hope that can shed some light on this.

-Onoitsu2
Amended on Tue 18 Sep 2007 10:37 AM by Onoitsu2
#2
I'd like to use a multi-line trigger to do it, because I'm capturing lots of wildcards from the real trigger I'm using and doing that with the variables would be really messy.

With the example you gave,

^Someone says \"Foo is true\"\n(?!Someone else says \"No it isn\'t\!\")$

I tried it out but I ran into problems because it'd match on a single line before the lookahead affected it. What I need is something that will match

Someone says "Foo is true"
where the second line is NOT
Someone else says "No it isn't!" and IS something else (rather than nill)

Sorry if this is badly explained...
Australia Forum Administrator #3
This variation on the suggestion worked for me:


<triggers>
  <trigger
   enabled="y"
   lines_to_match="2"
   match="\ASomeone says \&quot;Foo is true\&quot;\n(?!Someone else says \&quot;No it isn\'t\!\&quot;)\Z"
   multi_line="y"
   regexp="y"
   send_to="2"
   sequence="100"
  >
  <send>Matched!</send>
  </trigger>
</triggers>


You need to make sure you have a match on \Z at the end, to make sure you process the entire last line. I also added \A to the start.
#4
Thanks!
I did find an alternative way of doing it too, but your way is a little more elegant.