Skip to content

Wildcards

SharpMUSH has two wildcards, which $-commands and many functions understand: an asterisk (*) matches any number of characters, none included, and a question mark (?) matches exactly one.

Their most common use is to let people pass arguments to a $-command. A wave command that waves at someone:

> &cmd.wave me=$wave *: pose waves.

The * matches anything, so wave foo and wave bar both work. %0 to %9 hold what the first ten wildcards matched:

> &cmd.wave me=$wave *: pose waves to %0.
> wave Muse
Mike waves to Muse.

A backslash (\) before * or ? matches a literal asterisk or question mark. You usually have to write \\, so that the parser leaves one backslash for the match:

> think strmatch(foobar, ?*?)
1
> think strmatch(foobar, \\?*\\?)
0
> think strmatch(?foobar?, \\?*\\?)
1

The ** wildcard matches attribute names across levels of an attribute tree: see attribute trees browsing.

Regular expressions match strings with more control than wildcards, and more to learn: see regexp.

::: seealso