Having an optional target in an alias

Posted by Tony Chamberlain on Wed 10 Aug 2016 07:45 PM — 4 posts, 17,090 views.

#0
I tried searching various helpfiles and searched this forum for any subject with alias but couldn't find exactly the answer I needed.

I programming an aliaas on aardwolf mushclient. I have tried to combine the following two aliases:
Note: I created a MushClient variable called Heal
Heal set to Cure Light
Both aliases have Enabled, Regular Expression and Expand Variables checked.

Alias 1:
^zz$
cast '@Heal'

Aliast 2:
^zz (.*)$
cast '@Heal' %1

This works great if type zz
I get cast 'cure light' (which is on me)
or typeing zz joe
I get cast 'cure light' joe

However if i remove Alias 1, whenever i just type zz
the mud returns : Unknown command please check help files.

It seems to require there be soemthing there to capture. I tried various combinations of ?, ?: and using a (.*|) to try to get it to work if nothing was there. Is this possible in regexp to have it match if nothing is there and have %1 just be ""
Amended on Wed 10 Aug 2016 09:31 PM by Tony Chamberlain
Australia Forum Administrator #1
Template:faq=50
Please read the MUSHclient FAQ - point 50.
#2
Thanks. Actually what I tried is almost exactly what that FAQ says. IF anyone else has this problem I finally noticed what i was doing wrong:

Whenever I tried:
^zz (.*)?$ it would fail because I had a space between zz and target, which regexp would look for and fail to find.

You have to have to have:
^zz(.*)?$ with no spaces at all.

Thanks again for the help.
Amended on Wed 10 Aug 2016 09:41 PM by Tony Chamberlain
Australia Forum Administrator #3
Yes, or put the space in the optional part, as the FAQ says:


^zz( .*)?$


Now that matches on zz (but not zzfoo) because you have the space there.