Reply to this subject
Start a new subject
 
Refresh page
| Posted by |
Poromenos
Greece (1,037 posts) bio
|
| Date |
Mon 26 Apr 2004 06:08 PM (UTC) [ quote
] |
| 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 (18,772 posts) bio
Forum Administrator |
| Date |
Reply #1 on Mon 26 Apr 2004 09:31 PM (UTC) [ quote
] 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:
- 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.
- 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) [ quote
] |
| 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) [ quote
] |
| 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 (18,772 posts) bio
Forum Administrator |
| Date |
Reply #4 on Mon 26 Apr 2004 10:59 PM (UTC) [ quote
] |
| 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) [ quote
] |
| 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.
1,500 views.
Reply to this subject
Start a new subject
 
Refresh page
top
Comments to:
Gammon Software support
Forum RSS feed ( http://www.gammon.com.au/rss/forum.xml )