TeensyMud - 'A ruby mud server.'

Subject: Using regex on command args
Subject: Using regex on command args
Author: Massaria
Posted: 01/28/2006 10:32AM


I've figured (finally) that the args passed to my cmd-files are always strings, and while it's not altogether bad, it's hard to filter out digits from an argument - at least I can't figure how.
Is there a way, or failing that, a way to make it pass along the args in an unmodified form?

Thanks
Mass.

reply
Subject: Using regex on command args
Author: Massaria
Posted: 01/28/2006 01:20PM

Massaria wrote:
>..., it's hard to filter out digits from an argument - at least I can't figure how.

Ah. I feared a really messed up regex, but it seems
args =~ /([ABCD]+)/

does the trick of finding A-D up until something else comes along.

yay me! ;-)

reply
Subject: Using regex on command args
Author: Tyche
Posted: 01/28/2006 05:06PM

Massaria wrote:
> Massaria wrote:
> >..., it's hard to filter out digits from an argument - at least I can't figure how.
>
> Ah. I feared a really messed up regex, but it seems
>
> args =~ /([ABCD]+)/
> 

> does the trick of finding A-D up until something else comes along.
>
> yay me! ;-)

Yep..
\w is a shortcut for [0-9A-Za-z_]
\d is a shortcut for [0-9]

I pass the whole string minus the command itself to args. I figure each command would have it's own syntax. I do plan on including some routines I have laying about here in a utility library.

I have one that works very close to what a Diku/Merc does. It takes the command string and builds an array. It understands single and double quoting. It wouldn't be hard to coerce to do automatic conversions of subparameters into integers or floats.



reply