Wild Routines


The Wild Routines implements basic wildcard matching and the escaping of wildcards within regular strings.

The Wild_EQ() function takes a wildcard spec and a regular string and returns "true" if there is a match. The wildcard characters are specified below.

The Wild_escapeWildcards() function takes a string pointer and returns an MBuf object with any wildcard characters escaped with backslashes. This allows the string or derivations of the string to be used as a wildcard spec without the characters being interpreted as anything other than literal matches.

Wildcard Characters

You may specify the following wildcard characters in the match-spec string:

The character class specifies a list of potential matching (or non-matching) characters between the '[' and the ']'. You can specify a range of characters by separating the start and the end with a '-'. You can specify a non-matching set of characters by starting the list with '^'. If you want to specify ']', '-', '^', or '\' in the set of characters, either precede the character with a backslash, or put the character in a position that it cannot be interpreted as having special meaning. For instance, ']' can be placed first in the list (possibly after a '^') without terminating the list, '-' can be placed either first (possibly after '^') or last in the list without being interpreted as a range, and '^' can appear anywhere but as the very first character without having special meaning.

For example, "[0-9]" matches all digits, "[A-Za-z0-9_-]" matches all alphanumeric characters plus dash and underscore, and "[^A-Z]" matches anything that is not an upper-case letter.

My version of the wild-card code has been enhanced to provide several backslash shortcuts (that will be familiar to perl regex users):

Any space character (like specifying [\t ]).
Any non-space character (like specifying [^\t ]).
Any digit (like specifying [0-9]).
Any non-digit (like specifying [^0-9]).
Any word character (often the same as [A-Za-z0-9_]).
Any non-word character (often the same as [^A-Za-z0-9_]).
A newline character.
A carriage-return character.
A tab character.
An escape character.
A form-feed character.
An audible bell character.
A backspace character.

Note that you can specify these values both outside and inside a character class.