Show Menu

JavaScript RegExp Cheat Sheet by

JavaScript Regular Expresion
regular     javascript     regexp     js     expresion

Legend

|r require,
|o option,
>re­turn,
re - RegExp,
str - String

Properties

regexp.co­nst­ructor
>Re­ference
regexp.global
>Bo­olean
regexp.ig­nor­eCase
>Bo­olean
regexp.mu­ltiline
>Bo­olean
regexp.la­stIndex
>Number
regexp.source
>String
legend:
> Return

Methods

str.ma­tch­(re­gexp|r)
>Array
str.re­pla­ce(­reg­exp|r, nvalue|r)
>String
str.se­arc­h(r­ege­xp|r)
>Number
re.exe­c(s­tri­ng|r)
>Array
re.tes­t(s­tri­ng|r)
>Bo­olean
re.com­pil­e(r­egexp|r ,modif­ier)*
*co­mpile() was deprecated in JavaScript version 1.5.

Quanti­fiers

^n
any string with n at the beginning of it
n$
any string with n at the end of it
n+
at least one n
n*
zero or more
n?
zero or one
n{3}
Exactly 3 of n
n{3,}
3 or more
n{3,6}
Between 3 and 6 of n
?=n
followed by a specific string n
?!n
not followed by a specific string n
 

Create RegExp

var re = new RegExp­('p­att­ern­','­mod');
or more simply:
var re = /patte­rn/­mod­ifiers;

Brackets

[abc]
any character between the brackets
[^abc]
any character NOT between the brackets
[0-9]
digit between the brackets
[^0-9]
digit NOT between the brackets
(x|y)
x or y
Brackets are used to find a range of characters

Metach­ara­cters

.
single character, except newline or line terminator
\w
word character
\W
non-word character
\d
digit
\D
non-digit
\s
whitespace
\S
non-wh­ite­space
\b
beginn­ing/end of a word
\B
not at the beginn­ing/end of a word
\0
NUL character
\n
new line
\f
form feed
\r
carriage
\t
tab
\v
vertical tab
 

Modiefiers

g
global
i
case-i­nse­nsitive
m
multiline

g Modifier

The g modifier is used to perform a global match (find all matches rather than stopping after the first match).
Tip: To perform a global, case-i­nse­nsitive search, use this modifier together with the "­i" modifier.
Tip: Use the global property to specify whether or not the g modifier is set.

RegExp­Obj­ect.global >true

i Modifier

The i modifier is used to perform case-i­nse­nsitive matching.
Tip: Use the ignoreCase property to check whether or not the "­i" modifier is set.

RegExp­Obj­ect.ig­nor­eCase >true

m Modifier

The m modifier treat beginning (^) and end ($) characters to match the beginning or end of each line of a string (delimited by \n or \r), rather than just the beginning or end of the string.
Note: The m modifier is case-s­ens­itive and will stop the search after the first match. To perform a global, case-i­nse­nsi­tive, multiline search, use this modifier together with "­g" and "­i".
Tip: Use the multiline property to specify whether or not the m modifier is set.

RegExp­Obj­ect.mu­ltiline >true

Download the JavaScript RegExp Cheat Sheet

1 Page
//media.cheatography.com/storage/thumb/savagedesign_javascript-regexp.750.jpg

PDF (recommended)

Alternative Downloads

Share This Cheat Sheet!

 

Comments

DaveChild DaveChild, 13:59 5 Aug 14

Great cheat sheet! This is awesome.

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          JavaScript Cheat Sheet
          jasmine JS testing Cheat Sheet