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


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Simple Match

Simple Match

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


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

Posted by Ked   Russia  (524 posts)  [Biography] 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

[Go to top] top

Posted by Poromenos   Greece  (1,037 posts)  [Biography] 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!
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] 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
[Go to top] top

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

Posted by Ked   Russia  (524 posts)  [Biography] 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 :)
[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.


15,082 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 HostDash]