Gammon Forum
Entire forum
MUSHclient
Tips and tricks
regular expressions for **
regular expressions for **
|
It is now over 60 days since the last post. This thread is closed.
  Refresh page
Posted by
| ErockMahan
(81 posts) bio
|
Date
| Tue 25 Mar 2008 06:50 PM (UTC) |
Message
| I want a trigger to activate on
Bob tells you *
but not
** Bob tells you *
Of course, it won't always be Bob, so I replace his name with *, which leaves me with
** * tells you *.
Converting it to a regular expression, I now have:
^\*\** tells you *$
But I can't get it to work like that, and yes the 'regular expression' box is checked. | top |
|
Posted by
| Nick Gammon
Australia (22,975 posts) bio
Forum Administrator |
Date
| Reply #1 on Tue 25 Mar 2008 08:18 PM (UTC) |
Message
|
Quote:
Converting it to a regular expression, I now have:
^\*\** tells you *$
This won't work for a couple of reasons. For one thing, you wanted things that don't have the 2 asterisks, whereas this will match if you do.
Second, in a regular expression you need to use .* to match anything, so it would be more like:
^\*\*(.*) tells you (.*)$
The brackets make the wildcards get returned as %1, %2 etc.
However to solve your problem, the simple thing is to simply make the regexp match on a name. I assume names must be A-Z? So try this:
<triggers>
<trigger
enabled="y"
match="^([A-Za-z]+) tells you (.*)$"
regexp="y"
send_to="2"
sequence="100"
>
<send>person = %1
what s/he said = %2</send>
</trigger>
</triggers>
What this does is make sure that the first word consists of A-Z or a-z (upper or lower case).
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | top |
|
Posted by
| Thalir
(13 posts) bio
|
Date
| Reply #2 on Thu 05 Jun 2008 09:00 AM (UTC) Amended on Thu 05 Jun 2008 10:35 AM (UTC) by Thalir
|
Message
| Apologies, I'd like to borrow this thread.
How may I capture "Apple Bat Tree" in the following? Assuming there are multiple spaces between "Tree" and "(blah)" -->
Apple Bat Tree (blah)
I'm currently using:
[A-Za-z\s]+
But this captures the multiple spaces between the last word and the brackets too.
Thank you in advance.
| top |
|
Posted by
| Nick Gammon
Australia (22,975 posts) bio
Forum Administrator |
Date
| Reply #3 on Thu 05 Jun 2008 09:54 AM (UTC) Amended on Thu 05 Jun 2008 09:55 AM (UTC) by Nick Gammon
|
Message
| To a certain extent your problem is undefined. I hope you mean two or more spaces after Tree, otherwise it is hard to know where the first part ends and the second part starts. However this works for me:
<triggers>
<trigger
custom_colour="2"
enabled="y"
match="^(([A-Za-z]+\s)+)\s+(.*)"
regexp="y"
send_to="2"
sequence="100"
>
<send>
%%1 = %1
%%2 = %2
%%3 = %3
</send>
</trigger>
</triggers>
Testing that against:
Apple Bat Tree testing 1 2 3
gives:
%1 = Apple Bat Tree
%2 = Tree
%3 = testing 1 2 3
What I have done here is grouped things.
[A-Za-z]+ gives you a word, and then we follow it by a single space: \s
That means that: ([A-Za-z]+\s)+
is one or more of those things (a word followed by one space).
Then we have: \s+(.*)
... which is another space, followed by the rest of the line.
If you can't rely on the second space, where would you break up:
every good boy deserves fruit
You need some sort of characteristic that defines the second group as being different from the first one.
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | top |
|
Posted by
| Thalir
(13 posts) bio
|
Date
| Reply #4 on Thu 05 Jun 2008 10:49 AM (UTC) |
Message
| Thanks, that did 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,587 views.
It is now over 60 days since the last post. This thread is closed.
  Refresh page
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.