[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]  Regex question
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Regex question

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


Posted by Poromenos   Greece  (1,037 posts)  [Biography] bio
Date Mon 26 Apr 2004 06:08 PM (UTC)
Message
<hp[1953/1953]>Poromenos tells you 'stats'

The "Poromenos tells you 'stats'" part is white. Is there any way i can also match everything before Poromenos, to avoid the following:
Nick tells you 'Poromenos tells you 'stats'

with the trigger "([A-Za-z]+) tells you \'stats\'$" this would match on Poromenos, and not on Nick. Is there any way to make it match on "Nick tells you 'Poromenos" instead of just Poromenos? The prompt is not white, and I need colour matching to stay.

Vidi, Vici, Veni.
http://porocrom.poromenos.org/ Read it!
[Go to top] top

Posted by Nick Gammon   Australia  (21,386 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Mon 26 Apr 2004 09:31 PM (UTC)

Amended on Mon 26 Apr 2004 09:32 PM (UTC) by Nick Gammon

Message
What you can do here is use an "assertion". This checks things but does not consume characters, so the matching text is still just what it was before so the colour matching will still be on the correct portion.

If you look at:


http://mushclient.com/pcre/pcrepattern.html#SEC15


You will see the write-up about assertions. In your case you want a look-behind assertion, because you want to make sure the text that *precedes* the matching text is, or is not, a certain thing. The limitation of look-behind assertions is that they have to be a fixed length, so you need to not match a variable thing but a fixed thing.

Two things you could do:


  1. Check that the character *before* the text "Poromenos tells you 'stats'" *is* a ">" symbol. That would exclude the case of "Nick tells you 'Poromenos tells you 'stats'", however if Nick was smart he might say "Nick tells you '>Poromenos tells you 'stats'" and defeat your test.

    To do this:


    Match: (?<=\>)([A-Za-z]+) tells you \'stats\'$


    The above is a positive assertion.

  2. Or, you could use a negative assertion. Check that the text is *not* preceded by "tells you '", like this:


    Match: (?<!tells you ')\b([A-Za-z]+) tells you \'stats\'$


    In this case I had to add the \b (assert word boundary) otherwise it matched on "oromenos tells you 'stats'" (in other words, the wildcard consumed the P and then found that "oromenos" was not preceded by "tells you '" and found a match. However the \b forces the match on whoever tells you to be a whole word and not a part word.


These assertions are pretty powerful stuff. :)

- Nick Gammon

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

Posted by Poromenos   Greece  (1,037 posts)  [Biography] bio
Date Reply #2 on Mon 26 Apr 2004 10:25 PM (UTC)
Message
Ah great, I didn't know that, thanks!

Vidi, Vici, Veni.
http://porocrom.poromenos.org/ Read it!
[Go to top] top

Posted by Poromenos   Greece  (1,037 posts)  [Biography] bio
Date Reply #3 on Mon 26 Apr 2004 10:31 PM (UTC)
Message
Hm, assertions have to be fixed-length, no? So even if I use a negative assertion, someone could do:
Nick tells you '' Nick tells you 'hi'
and defeat it... Can i add a wildcard somehow?

Vidi, Vici, Veni.
http://porocrom.poromenos.org/ Read it!
[Go to top] top

Posted by Nick Gammon   Australia  (21,386 posts)  [Biography] bio   Forum Administrator
Date Reply #4 on Mon 26 Apr 2004 10:59 PM (UTC)
Message
Why do you need the wildcard? My negative assertion picked up the words "... tells you". Isn't that enough? By omitting *who* tells you (which you don't care about) you pick up the spoof line.

- Nick Gammon

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

Posted by Poromenos   Greece  (1,037 posts)  [Biography] bio
Date Reply #5 on Tue 27 Apr 2004 09:24 AM (UTC)
Message
You're right... I guess I can tell if they're spoofing or not... I'll try something and see.

Vidi, Vici, Veni.
http://porocrom.poromenos.org/ Read it!
[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.


3,601 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]