Metacharacters
A metacharacter is a character that has a special meaning during pattern processing. You use metacharacters in regular expressions to define the search criteria and any text manipulations.
Search string metacharacters are different from replacement string metacharacters.
Search string metacharacters
The following table lists metacharacters for extended regular expression searches.
If you use basic regular expressions, not all metacharacters are supported. The function of the backslash character is reversed. You must include a backslash character before all metacharacters.
Metacharacter | Action |
---|---|
^ | Beginning of line |
$ | End of line |
| | Or Not applicable to basic regular expressions. |
[abc] | Match any character enclosed in the brackets |
[^abc] | Match any character not enclosed in the brackets |
[a-z] | Match the range of characters specified by the hyphen |
[:cclass:] | Use the character list that is specified by cclass:
These classes are valid for single-byte character sets. |
[=cname=] | Substitute the character name that is specified by cname with the
corresponding character code. For a list of character names, see Regex character names. |
. | Match any single character. |
( ) | Group the regular expression within the parentheses. |
? | Match zero or one of the preceding expression. Not applicable to basic regular expressions. |
* | Match zero, one, or many of the preceding expression. |
+ | Match one or many of the preceding expression. Not applicable to basic regular expressions. |
\ | Use the literal meaning of the metacharacter. For basic regular expressions, treat the next character as a metacharacter. |
Replacement string metacharacters
The following table lists metacharacters for extended regular expression searches.
If you use basic regular expressions, not all metacharacters are supported. The function of the backslash character is reversed. You must include a backslash character before all metacharacters.
Metacharacter | Action |
---|---|
& | Reference the entire matched text for string substitution. For example, the statement
|
\n | Reference the subgroup n within the matched text, where
n is an integer 0-9. \0 and & have identical actions. \1 - \9 substitute the corresponding subgroup. For example, the statement For example, the statement Not applicable to basic regular expressions. |
\ | Use the literal meaning of the metacharacter, for example, \& escapes
the Ampersand symbol and \\ escapes the backslash.For basic regular expressions, treat the next character as a metacharacter. |