[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Regular expression question
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Regular expression question

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Gaem   (10 posts)  [Biography] 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.
[Go to top] top

Posted by Onoitsu2   USA  (248 posts)  [Biography] 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
[Go to top] top

Posted by Gaem   (10 posts)  [Biography] 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...
[Go to top] top

Posted by Nick Gammon   Australia  (21,652 posts)  [Biography] 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 \&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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Gaem   (10 posts)  [Biography] 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.
[Go to top] 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.


4,767 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]