Regular Expression Pattern Matching

Regular expressions have recently been introduced into PennMUSH (and TinyMUSH as well I believe -- I think that's where PennMUSH got the idea for them from). These expressions allow the coder finer control over pattern matching than the traditional glob style pattern matching everyone is used to.

So what's so great about regular expressions? Because of the control they allow you, you could setup a command such as:

&command object=$^my number is ([0-9]+):@pemit %#=You chose your number to be %1. You full command line you typed was %0.
@set object/command=REGEXP
Now you see rather than having to have an @switch using a isnum() check, you can just require a number for the command. This does mean that if they input the command wrong, for example with text, that they will get the "Huh" message. If you really want to catch for that, you still can by making a second command that would be anything not matching 0-9, and give them some sort of error message then.

You can also do regular expression matching with regmatch() (in PennMUSH at least, I assume so in Tiny as well) within your function code. Often where a glob style pattern matching will be expensive to use, requiring you to split up the arguments yourself, a regular expression will do it in the regmatch() command with no problem. For this reason if no others, you should at least take a look at the regular expression facilities and consider using them.

For more help on regular expressions, see 'help regexp' and 'help regmatch' on PennMUSH (probably Tiny too).

 Home MUSH Theory Sitemap