Searching for Special Characters

In regular expression syntax, most non-alphanumeric characters are treated as special characters. These characters, called "metacharacters", include asterisks, question marks, dots, slashes, and other non-alphanumeric characters. In order to search for a metacharacter without using its special attribute, precede it with a backslash "\" to change it into a literal character. For example, to build a regex to search for a .txt file, precede the dot with a backslash \.txt to prevent the dot's special function, a wildcard search. The backslash, called an "escape character" in regex terminology, turns metacharacters into literal characters.

Precede the following metacharacters with a backslash "\" to search for them as literal characters:

^ $ + * ? . | ( ) { } [ ] \

Using the backslash "\" to escape special characters in a regular expression.

Example 1: Escape the dollar sign "$" to find the alphanumeric string "$100".

Example 2: Use the dot "." as a literal character to find a file called "email.txt".

Example 3: Escape the backslash "\" character to search for a Windows file.