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.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ General
➜ Simple Match
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| WRTIII
Canada (76 posts) Bio
|
| Date
| Mon 09 Jun 2003 11:59 PM (UTC) |
| Message
| *
*************************************
* GUIDE MESSAGE from Guide Lauricea *
*************************************
* "LIST! TEST"
*
I need to match this line
* "LIST! TEST"
I did a regular expression trigger set to match on
\* "LIST! *"
Then send %1 to varible list
Then I need to match on
* "LIST?"
and it tells the person the current list
The problem is
* "LIST! TEST"
Is not matching... | | Top |
|
| Posted by
| Ked
Russia (524 posts) Bio
|
| Date
| Reply #1 on Tue 10 Jun 2003 03:00 AM (UTC) |
| Message
| It's not matching because * doesn't pick up a wildcard in regexp. It simply means 'any number of whatever precedes'. If you want a wildcard to match on any number of anything you can use: '.*' A period in regexp stands for anything. And if you want the wildcard to be captured (which you obviously do) enclose it in parentheses, otherwise it'll match but won't be available to you to work with. So the trigger would look like:
\* "LIST! (.*)"
Also, I am not sure if ! and " need or need not be escaped in regexp, so if it doesn't match try escaping first the ! then the "'s
| | Top |
|
| Posted by
| Poromenos
Greece (1,037 posts) Bio
|
| Date
| Reply #2 on Tue 10 Jun 2003 12:28 PM (UTC) |
| Message
| | I think you need to escape them. By the way, what's the difference between (.*) and (.*?)? |
Vidi, Vici, Veni.
http://porocrom.poromenos.org/ Read it! | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #3 on Tue 10 Jun 2003 10:22 PM (UTC) |
| Message
| Generally speaking there is no harm in escaping (putting a backslash before) non-alphabetic characters, especially if things aren't working how you expect.
As for the extra question-mark, see:
http://www.gammon.com.au/scripts/doc.php?general=regexp
Search for the word "greedy" (using the web browser search) and you will find a reference to it near the botom of the page.
Basically the difference is that without the ? (that is, the sub-expression (.*) ) matches the most it can, whilst with it (that is, the sub-expression (.*?) ) matches the least it can, consistent with matching at all.
The situation might arise in a case like this:
match: (.*)\s(.*?)
(The \s matches a space character the two wildcards).
Now say the string being matched against was:
"Nick goes shopping"
Clearly there are two possible matches here for wildcards 1 and 2:
First case: 1 = "Nick goes", 2 = "shopping"
Second case: 1 = "Nick", 2 = "goes shopping"
However the greedy one will match more, thus the results will be the first case (the greedy wildcard will get "Nick goes", the ungreedy one will get "shopping").
The default behaviour when you click the "convert to regular expression" button in triggers and aliases, is to use the non-greedy version, because usually you want a wildcard to be the first word.
For instance, say I had a trigger to match on:
* tells you: *
And then Poromenos send me a tell about Magnum:
"Poromenos tells you: today I got the message: Magnum tells you: blah blah"
Again you want the less greedy match (because there are 2 "tells you:" in that line).
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Ked
Russia (524 posts) Bio
|
| Date
| Reply #4 on Tue 10 Jun 2003 11:05 PM (UTC) |
| Message
| (.*?) is the 'third' use of the question mark, that is - as a quantifier minimizer. Basically a question mark which follows another quantifier (including the questionmark itself, like '\d??') tells that quantifier to match as few times as possible. By default any quantifier will match as many times as possible. The example from the docs is the use of: '/\*.*/\*' regexp to match on the string of code with two comments in it:
/* first comment */ some code /* second comment */
The '.*' in the above regexp would match everything between the first /* and last */, including the code, due to the greediness of the quantifier. However using '/\*.*?/\*' matches the first comment in that line (unless it repeats on same line), since ? limits the matches of .* to the point at which the first */ is encountered. So basically (.*?) means - match as few times as necessary to match the line but not more. | | Top |
|
| Posted by
| Ked
Russia (524 posts) Bio
|
| Date
| Reply #5 on Tue 10 Jun 2003 11:07 PM (UTC) |
| Message
| | Well doh - I guess that reply hung on my screen offline for a bit too long. But 2 explanations are twice as much as one :) | | 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.
22,683 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top