Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Entire forum
➜ MUSHclient
➜ General
➜ Regular expression question
Regular expression question
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Gaem
(10 posts) Bio
|
Date
| Tue 18 Sep 2007 10:07 AM (UTC) |
Message
| 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. | Top |
|
Posted by
| Onoitsu2
USA (248 posts) Bio
|
Date
| Reply #1 on Tue 18 Sep 2007 10:27 AM (UTC) Amended on Tue 18 Sep 2007 10:37 AM (UTC) by Onoitsu2
|
Message
| 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 | Top |
|
Posted by
| Gaem
(10 posts) Bio
|
Date
| Reply #2 on Tue 18 Sep 2007 06:20 PM (UTC) |
Message
| 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... | Top |
|
Posted by
| Nick Gammon
Australia (23,121 posts) Bio
Forum Administrator |
Date
| Reply #3 on Tue 18 Sep 2007 09:28 PM (UTC) |
Message
| This variation on the suggestion worked for me:
<triggers>
<trigger
enabled="y"
lines_to_match="2"
match="\ASomeone says \"Foo is true\"\n(?!Someone else says \"No it isn\'t\!\")\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. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Gaem
(10 posts) Bio
|
Date
| Reply #4 on Tue 18 Sep 2007 09:46 PM (UTC) |
Message
| Thanks!
I did find an alternative way of doing it too, but your way is a little more elegant. | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
16,348 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top