Wildcard patterns can be used in many functions in Opus, including:
As well as regular expressions, Opus supports a more simple wildcard system, called the standard pattern matching system. When using wildcards, you specify a pattern consisting of a mix of literal text and special wildcard tokens. Each token is used to match one or more characters in the target string. As a simple example, the pattern *.doc matches anything that ends with the literal characters .doc (or in other words, document files).
Token | Description |
---|---|
# |
The character or expression following the # is repeated 0 or more times. For example: |
? |
Matches any single character. For example: |
| |
Used to separate multiple expressions, any of which may match (effectively an or operator). For example: |
~ |
This is the not operator, it negates the following expression. For example: |
() |
Parentheses are used to combine multiple characters into an expression. If we take the above example of a#(xyz)b, the parentheses are used to form xyz into a single expression. Without the brackets (i.e. a#xyzb) only the x would be seen to follow the # character - yzb would be treated literally. For example: |
[] |
Matches any single character in the set of specified characters. For example: |
[~] |
Matches any character not in the set of specified characters. See [] for information on how the set is defined. For example: |
* |
Matches any number of characters, including zero. This is a synonym for #?. |
' |
The apostrophe is called the escape character. Any character in the pattern string that isn't a wildcard token is taken as a literal character - literal characters have to match the characters in the target string exactly. However, if actually want to use a wildcard token as a literal character itself, you must escape the token by preceding it with an apostrophe. For example: |
grp: |
When using wildcards to match filenames this is a shorthand way to refer to all the file extensions defined by a file type group. This is much easier to read (and type!), and if you ever add or remove file types from the group in question, any patterns which refer to the group will automatically reflect the new changes. For example: |