This shows you the differences between two versions of the page.
— |
patterns [2006/08/29 16:08] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | =====Pattern Matching===== | ||
+ | |||
+ | Literally, any string is a pattern. In general, though, a pattern is a | ||
+ | string intended to match, or be matched by, one or more other strings. The | ||
+ | pattern will usually contain one or more wildcards, but it doesn't need to. | ||
+ | |||
+ | The following wildcard characters are supported: | ||
+ | |||
+ | |* | matches zero or more characters | | ||
+ | |% | matches zero or more characters, except spaces | | ||
+ | |? | matches exactly one character | | ||
+ | |||
+ | Assuming we have a variable $foo set to "hello there": | ||
+ | |||
+ | |hello* | /* pattern matches */ | | ||
+ | |hello% | /* pattern does not match */ | | ||
+ | |hello%?% | /* pattern matches */ | | ||
+ | |h?llo?th?r? | /* pattern matches */ | | ||
+ | |||
+ | Patterns may also contain multiple "branches". Each branch is tested when | ||
+ | a match attempt is made. Branches are formed with the \\[ \\] construct. | ||
+ | For example: | ||
+ | |||
+ | \\[foo bar\\]blah /* matches "fooblah" and "barblah" */ | ||
+ | |||
+ | The branching construct may be used anywhere that wildcards are used, | ||
+ | including the various pattern matching functions, and in hook events. | ||