Register forum user name Search FAQ

Gammon Forum

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 ➜ Regex question

Regex question

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


Posted by Poromenos   Greece  (1,037 posts)  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!
Top

Posted by Nick Gammon   Australia  (23,120 posts)  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
Top

Posted by Poromenos   Greece  (1,037 posts)  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!
Top

Posted by Poromenos   Greece  (1,037 posts)  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!
Top

Posted by Nick Gammon   Australia  (23,120 posts)  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
Top

Posted by Poromenos   Greece  (1,037 posts)  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!
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.


15,668 views.

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

Go to topic:           Search the forum


[Go to top] top

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