Processing an alias that might have zero wildcards

Posted by Zylogia on Sun 16 Mar 2008 03:46 PM — 5 posts, 22,454 views.

#0
I want to supersede an in-game command, "pose" with an alias of the same name, that does some additional processing. The details of the added stuff probably don't matter for this question.

I've developed a script called fn_pose that works fine. The problem occurs in the calling of the script.

I have defined an alias, pose *

If on the in-game command line I type,
pose <space> <enter>
then the function runs.

If on the command line I type,
pose Several words <enter>
then the function runs fine

However, if I type just
pose <enter>
then the function does not run at all. Rather, the in-game command runs.

I've got a workaround, in that I now have 2 aliases, called pose
pose *

They both call the same function. (I test for nil as a wildcard, and then process OK.)

Now my question: Is there a more elegant solution than using two aliases like this?
Australia Forum Administrator #1
See: http://www.gammon.com.au/forum/?id=8220
Australia Forum Administrator #2
This question comes up every few months, so I have added it to the FAQ, see http://mushclient.com/faq point 50.

The FAQ item explains the whole thing in a bit more detail and gives a couple of suggestions about different approaches.
Netherlands #3
A little comment to the item you added in the FAQ.. Instead of using {0,1} you can also use ? instead. It means the same and is more commonly used in regular expressions for the 'it may or may not match' situation. Although, I suppose it is mostly a difference in taste. :)
Australia Forum Administrator #4
That's quite true. Instead of:


match="^heal( {1,}(.*)){0,1}$"


I could have written:


match="^heal( +(.*))?$"


The "+" means "one or more spaces" and the "?" means "zero or one of the previous item/group". That is more compact, and more frequently used, however arguably less clear.