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
➜ basic regular expression in an alias
|
basic regular expression in an alias
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| MushclientNewbie
USA (33 posts) Bio
|
| Date
| Mon 29 Nov 2004 10:06 PM (UTC) Amended on Mon 29 Nov 2004 10:07 PM (UTC) by MushclientNewbie
|
| Message
| My problem: I use aliases for long mud command inputs. Like, I imagine, most everyone does. Since I had started using MC so long ago I've fixed my problem in a sort of round about-way. I've been making two triggers for every single alias I use. For example:
<alias
match="ca *"
enabled="y"
sequence="100"
>
<send>commune 'armor' %1</send>
</alias>
<alias
match="ca"
enabled="y"
sequence="100"
>
<send>commune 'armor'</send>
</alias>
This way I could use the first alias 'ca *' to give armor to someone else while I could use the first alias 'ca' to give armor to myself quickly since the mud reads spells cast with no target as self-cast (offensive spells with no target are directed at your current combat target - which is nice when blinded since givning it a target just returns that the person can't be found).
It's worked fine up until now, but by now I'm awful tired of having my alias screen cluttered up with repeat alias after repeat alias. For now I've worked out this half-baked solution that looks like:
<alias
match="ca*"
enabled="y"
sequence="100"
>
<send>commune 'armor'%1</send>
</alias>
Which works fine until I enter something that starts with ca... like 'cackle.' I know regular expressions can take care of this. I've read through the helpfile on it and so far what I have (not working) is this:
<alias
match="^ca(| \*)"
enabled="y"
regexp="y"
sequence="100"
>
<send>commune 'armor' %1</send>
</alias>
No matter what I type or how hard I type it <^_^< all I ever get returned is "commune 'armor' " with that little space after it. Am I using the | operator wrong? Or is it just that it won't give me a 'match on nothing' choice? | | Top |
|
| Posted by
| Flannel
USA (1,230 posts) Bio
|
| Date
| Reply #1 on Mon 29 Nov 2004 10:50 PM (UTC) |
| Message
| |
| Posted by
| MushclientNewbie
USA (33 posts) Bio
|
| Date
| Reply #2 on Mon 29 Nov 2004 11:17 PM (UTC) Amended on Mon 29 Nov 2004 11:19 PM (UTC) by MushclientNewbie
|
| Message
| Thanks Flannel. It works:
<alias
match="^ca( .*)?$"
enabled="y"
regexp="y"
send_to="12"
sequence="100"
>
<send>if "%1" = "" then
Send "commune 'armor'"
else
Send "commune 'armor'%1"
end if</send>
</alias>
But why? When I try and break it down this is what I get...
^ is easy. That's there to make sure it matches at the beginning of a string so I don't fire it accidentally on something like, "He's in the can." Can doesn't match 'ca' but its the thought here that counts, right?
() matches any pattern inside. Here the pattern is " .*" space-period-asteric. Here is where I get a little confused. The period tells the mud that this expression matches on a single character and the asteric goes on further to say that it matches anything 0 times or more, right? So the insides of the pattern say that it matches anything with 0 or more spaces? Why didn't it need the \ operator to tell it that it's for a wildcard?
? then this says that all the previous stuff in the pattern can match once or not-at-all?
$ follows it all up to match on the not-at-all case for the 'ca' with nothing after it which runs the if "%1" = "" case. | | Top |
|
| Posted by
| Flannel
USA (1,230 posts) Bio
|
| Date
| Reply #3 on Mon 29 Nov 2004 11:24 PM (UTC) |
| Message
| the slash is only for special things, such as \n (for a newline) \d (for a digit) and such. a . is "anything" and then the * is a quantifier.
so, '.*' matches on ANYTHING.
and then we need a space in there, since otherwise we would match on 'cackle'. And the $ at the end is just like the ^ at the beginning, it makes sure we match the whole line, and dont skip anything important.
a backslash sequence is a more specific type of '.' it matches on 'any' of a specific type of thing.
|
~Flannel
Messiah of Rose
Eternity's Trials.
Clones are people two. | | Top |
|
| Posted by
| Shadowfyr
USA (1,791 posts) Bio
|
| Date
| Reply #5 on Mon 13 Dec 2004 05:05 PM (UTC) |
| Message
| Actually. + and * are nearly the same. They both mean "X or more of the character or group I follow." The difference is that * means "0 or more", while + means "1 or more". So basically, if you had two lines:
The duck.
The mad duck.
Then "The .* duck\." would match both lines, while "The .+ duck\." would only match the second line. BTW, I meantioned 'group' above. That means a trigger like "The (mad |sad |dead )*duck\.", which would match:
The mad duck.
The mad mad mad duck.
The mad sad dead mad duck.
Or any other combination, since you are asking it not to just look for those specific words, but any number of them. Note also the location of the spaces and '*duck'. If you think about it, the reason is that "The (mad|sad|dead)* duck\." would imply a line like 'The madsaddead duck.', which obviously won't work, so the spaces have to be defined in the groups themselves. | | Top |
|
| Posted by
| Nick Gammon
Australia (23,165 posts) Bio
Forum Administrator |
| Date
| Reply #6 on Mon 13 Dec 2004 08:52 PM (UTC) |
| Message
| Plus, you can be more specific, like I did in the other recent post about your skills. Something like:
This matches between exactly 2 and 4 of "mad " so it would match only
The mad mad duck
The mad mad mad duck
The mad mad mad mad duck
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | 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.
30,043 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top