Single-Character Regular Expressions
This section describes the rules for creating regular expressions (REs). Regular expressions can be used to match complex string patterns.
The following rules determine one-character REs that match a single character:
- Special characters are:
+ * ? . [ ^ $ ( ) { | \
- Any character that is not a special character matches itself.
- A backslash (\) followed by any special character matches the literal character itself, that is, the backslash escapes the special character.
- A period (.) matches any character, for example, ".umpty" matches either "Humpty" or "Dumpty."
- A set of characters enclosed in brackets ([]) is a one-character RE that matches any of the characters in that set. For example, "[akm]" matches an "a", "k", or "m".
- Any regular expression can be followed by one of the following suffixes: {m,n} forces a match of m through n (inclusive) occurrences of the preceding regular expression. The suffix {m,} forces a match of at least m occurrences of the preceding regular expression. The syntax {,n} is not allowed.
- A range of characters can be indicated with a dash. For example, "[a-z]" matches any lowercase letter. However, if the first character of the set is the caret (^), the RE matches any character except those in the set. It does not match the empty string. For example: [^akm] matches any character except "a", "k", or "m". The caret loses its special meaning if it is not the first character of the set.
- All regular expressions can be made case insensitive by substituting individual characters with character sets, for example, [Nn][Ii][Cc][Kk].
AllaireDoc@allaire.com
Copyright © 1998, Allaire Corporation. All rights reserved.