You are on page 1of 2

Search for Special Characters

Regex supports the following special characters that can be


included as characters:

 newline '\n'
 carriage return '\r'
 tab '\t'
 Whitespace '\s'
 Null character '\0'
 Form feed '\f'
 ASCII character \nnn

Metacharacter Description
. Any single character
^ Match the beginning of a line
$ Match the end of a line
a|b Match either a or b
\d any digit
\D Any non-digit character
\w Any word character
\W Any non-word character
\s matches any whitespace character
\S Match any non-whitespace character
\b Matches a word boundary
\B Match must not occur on a \b boundary.
[\b] Backspace character
\xYY Match hex character YY
\ddd Octal character ddd
const emailRegex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]
{2,4}$/;

Key components of the regex pattern:

 ^: Start of the string.


 [a-zA-Z0-9._-]+:
Match one or more alphanumeric characters, dots,
underscores, or hyphens for the username part.
 @: Match the "@" symbol.
 [a-zA-Z0-9.-]+:
Match one or more alphanumeric characters, dots, or
hyphens for the domain name.
 \.:Match a period (dot), which separates the domain name and top-
level domain (TLD).
 [a-zA-Z]{2,4}: Match the TLD, consisting of 2 to 4 alphabetical
characters.
 $: End of the string.

You might also like