Home  • Programming • JavaScript

Regular Expression Cheat Sheet

regular expression
Meta-characters Description
A
Matches only at the beginning of the string.

Matches a word boundary.
B
Matches anything but a word boundary.
d
Matches a digit character. This is the same as [0-9].
D
Matches a non-digit character.
s
Matches a white-space character.
S
Matches a nonwhite-space character.
[ ]
Encloses a character range
( )
Encloses a character grouping or defines a back reference.
$
Matches the end of the line.
^
Matches the beginning of the line.
^
Matches any character except for the newline
Quotes the next meta-character.
w
Matches any string containing solely underscore and alphanumeric characters. This is the same as [a-zA-Z0-9_]
W
Matches a string, omitting the underscore and alphanumeric characters.
.
Matches any string except some special symbol and white space character.
Quantifiers Description
+
Matches at least one character.
*
Matches zero or more characters.
?
Matches only zero or one character
{m}
Matches exactly m number of characters.
{m,}
Matches ranging from m to unlimited number of characters.
{m,n}
Matches ranging m to n number of characters.
Modifiers Description
I
Perform a case-insensitive search.
G
Find all occurrences (perform a global search).
M
Treat a string as (m for multiple) several lines.
S
Treat a string as a single line, ignoring any newline characters found within; this accomplishes just the opposite of the m modifier.
X
Ignore white space and comments within the regular expression.
U
Stop at the first match. Matches the pattern as many times as possible rather than just stop at the first match.
Predefined Character Ranges Description
[:alpha:]
Lowercase and uppercase alphabetical characters. This can also be specified as [A-Za-z].
[:alnum:]
Lowercase and uppercase alphabetical characters and numberical digits. This can also be specified as [A-Za-z0-9].
[:cntrl:]
Control characters such as tab,escape, or backspace.
[:digit:]
Numerical digits 0 through 9. This can also be specified as [0-9].
[:graph:]
Printable characters found in the range of ASCII 33 to 126.
[:lower:]
Lowercase alphabetical characters. This can also be specified as [a-z].
[:punct:]
Punctuation characters, including ~ ` ! @ # $ % & * ( ) - _ + = { } [ ] : ; ' < > , . ? and /.
[:upper:]
Uppercase alphabetical characters. This can also be specified as [a-z].
[:space:]
White-space characters, including the space, horizontal tab, vertical tab, new line, form feed, aor carriage return.
[:xdigit:]
Hexadecimal characters, This can also be specified as [a-fA-F0-9].

Some of useful regular expression

Regular Expression for web developer

Comments 5


thanks sir..
Thumbs up
very effective article, thanks sir..
thanks sir
Great! Thumbs up

Share

Copyright © 2024. Powered by Intellect Software Ltd