Regular expressions can be hard to remember, no wonder you have landed on this page. Below you will find a full list of regular expressions you can use in JavaScript with their meaning explained.
Get access to 300+ webtips đź’Ś Level up your skills and master the art of frontend development with bite-sized tutorials.
We don't spam. Unsubscribe anytime.
Get Access to Webtips
Flags Flag Explanation g
Match globally i
Case insensitive matching m
Match on multiple lines when using anchors s
 (dotall)Makes .
to match new lines as well u
Unicode support
Anchors Regex Explanation ^a
Starts with the next character (a) z$
Ends with the preceding character (z)
Looking to improve your skills? Check out our interactive course to master JavaScript from start to finish.
Remove adsCharacter Classes Regex Explanation \w
Match for word \d
Match for digit \s
Match for whitespace \W
Match any character that is not a word \D
Match any character that is not a digit \S
Match any character that is not a whitespace [az]
Match any of "a" and "z" [^az]
Match any character that is not "a" and "z" [a-z]
Match a set of characters inside the brackets (a to z) .
Match everything expect a new line
Quantifiers and Alternations Regex Explanation a{4}
Match preceding token that is exactly 4 characters long a{2,4}
Match preceding token that is between 2 and 4 characters long a{2,}
Match preceding token longer than 2 characters a*
Match 0 or more of the preceding character a+
Match 1 or more of the preceding character a?
Match 0 or 1 of the preceding character a|z
Match “a” or “z”
Get access to 300+ webtips đź’Ś Level up your skills and master the art of frontend development with bite-sized tutorials.
We don't spam. Unsubscribe anytime.
Get Access to Webtips
Escaped Characters Regex Explanation \/
Escape a forward slash (char code 47) \\
Escape a backslash (char code 92) \.
Escape a dot (char code 46) \*
Escape an asterisk \t
Match tabs \n
Match new line \r
Match carriage return
Groups and Lookarounds Regex Explanation (2020)
Capturing group - group the expression when there is a match (?:2020)
Non-capturing group - don't capture the expression (?<year>2020)
Named capturing group - name the captured group as "year" (?=2020)
Positive lookahead - see if pattern is followed by the expression (?!2020)
Negative lookahead - see if pattern is not followed by the expression (?<=2020)
Positive lookbehind - see if pattern is preceded by the expression (?<!2020)
Negative lookbehind - see if pattern is not preceded by the expression
Looking to improve your skills? Check out our interactive course to master JavaScript from start to finish.
Remove adsJavaScript Functions Function Return value regex.exec('string')
Returns null
 or array
 containing the match  regex.test('string')
Returns true
 or false
 based on the provided string  string.match(/regex/g)
Returns null
 or array
 containing matches  string.matchAll(/regex/g)
Returns an empty array or RegExpStringIterator
string.search(/regex/g)
Returns index, returns -1
 if no match is found  string.replace(/regex/g, 'newString')
Returns a string where the matched expression is replaced with the second argument string.replaceAll(/regex/g, 'newString')
Returns a string where all occurrences of the matched expression are replaced with the second argument string.split(/regex/g)
Breaks the string into an array of substrings based on the expression
Tools Site Description regexr.com Test your regular expressions interactively regexper.com Visualize your regular expressions