Operators consist of one or more special characters.
Operator | Description | Example |
---|---|---|
Any literal character |
Match-self operator
This operator is represented by any literal character. Its definition is included for completeness only. It matches the character itself. |
t matches only the string t. It does not match the string tt. |
This operator is not represented by any character. |
Concatenation operator
It concatenates two regular expressions a and b. b is simply placed after a. The result is a regular expression that will match a string if a matches its first part and b matches the rest. |
xy matches xy. |
. |
Match-Any-Character operator
This operator is represented by a period. It matches any single printing or non-printing character. |
a.b matches any three-character string beginning with a and ending with b, such as axb, a5b, or a%b. |
* |
Match-Zero-or-More operator
This operator is represented by an asterisk. The "*" operator is always used following a literal character or a special character. It repeats the smallest possible preceding regular expression as many times as necessary to match the pattern, including one repetition and zero repetitions. |
fo* matches for example f, fo, and foo. |
{count} {min,} {min, max} |
Interval operators
The open interval operator is represented by "{". The close interval operator is represented by "}". Interval operators repeat the smallest possible preceding regular expression a specified number of times. |
{count} matches exactly <count> occurrences of the preceding regular expression. {min,} matches at least <min> occurrences of the preceding regular expression. {min,max} matches between <min> and <max> occurrences of the preceding regular expression. The interval is invalid if <min> is greater than <max>, or any of <count>, <min>, or <max> is outside the range 0 - 256. |
[ ] [^ ] |
Character Class operators
"[" and "]" are used in regular expressions as special characters to indicate a character class. A character class matches a single character, regardless of how many characters or character ranges are defined in the character class. Characters contained in the class can be listed individually. Alternatively, character ranges can be specified using the "-" range operator. A character class can contain as many individual characters as needed, and can contain multiple character ranges. A negated character class can also be specified. A negated character class consists of any character except the characters and/or ranges listed in the character class. A negated character class includes the "^" metacharacter as the first character in the list. Most special characters lose any special meaning inside a character class. The following characters still have a special meaning at certain positions within an expression.
Note: Empty character classes are invalid.
|
|
- |
Range operator
The range operator is represented by a hyphen: -. It specifies a range of characters when used inside a character class. |
b-f matches any character between
b and f: b, c, d,
e, or f. A-Z matches any capital letter. a-z matches any lower case letter. 0-9 matches any number. |
\ |
Escape operator
The escape operator is represented by a backslash \. It is used to quote certain special characters: If you need to use the literal value of a special character within an expression, then a backslash should be inserted before that special character to signal that the following character is to be treated literally. |