JavaScript Regex Cheatsheet

Regular Expression Basics
.Any character except newline
aThe character a
abThe string ab
a|ba or b
a*0 or more a's
\Escapes a special character
Regular Expression Quantifiers
*0 or more
+1 or more
?0 or 1
{2}Exactly 2
{2, 5}Between 2 and 5
{2,}2 or more
Default is greedy. Append ? for reluctant.
Regular Expression Groups
(...)Capturing group
(?:...)Non-capturing group
\YMatch the Y'th captured group
Regular Expression Character Classes
[ab-d]One character of: a, b, c, d
[^ab-d]One character except: a, b, c, d
[\b]Backspace character
\dOne digit
\DOne non-digit
\sOne whitespace
\SOne non-whitespace
\wOne word character
\WOne non-word character
Regular Expression Assertions
^Start of string
$End of string
\bWord boundary
\BNon-word boundary
(?=...)Positive lookahead
(?!...)Negative lookahead
Regular Expression Flags
gGlobal Match
iIgnore case
m^ and $ match start and end of line
Regular Expression Special Characters
\nNewline
\rCarriage return
\tTab
\0Null character
\YYYOctal character YYY
\xYYHexadecimal character YY
\uYYYYHexadecimal character YYYY
\cYControl character Y
Regular Expression Replacement
$$Inserts $
$&Insert entire match
$`Insert preceding string
$'Insert following string
$YInsert Y'th captured group

Comments

Popular posts from this blog

How to clear cache programmatically in JSP?

How to extend Liferay 6.2 session timeout by AJAX call?

How to get context path in JQuery?