FileConverterPro

Regex Cheatsheet

Complete regular expression cheatsheet and reference guide. Quick lookup for regex syntax, character classes, quantifiers, anchors, groups, lookaheads, and common patterns.

Runs entirely in your browser — files never uploaded

PatternDescriptionExampleMatch
.Any character except newlinea.cabc, aXc
\dAny digit [0-9]\d{3}123, 456
\DAny non-digit\D+abc, !@#
\wWord character [a-zA-Z0-9_]\w+hello, var_1
\WNon-word character\W!, @, #
\sWhitespace (space, tab, newline)a\sba b
\SNon-whitespace\S+hello
[abc]Any of a, b, or c[aeiou]a, e, i
[^abc]Any character except a, b, or c[^0-9]a, Z, !
[a-z]Any character in range a to z[A-Z]A, M, Z
PatternDescriptionExampleMatch
^Start of string (or line with m flag)^HelloHello world
$End of string (or line with m flag)world$Hello world
\bWord boundary\bcat\bcat (not catch)
\BNon-word boundary\Bcatscat (not cat)
PatternDescriptionExampleMatch
*0 or more (greedy)ab*cac, abc, abbc
+1 or more (greedy)ab+cabc, abbc
?0 or 1 (optional)colou?rcolor, colour
{n}Exactly n times\d{4}2024
{n,}n or more times\d{2,}12, 123, 1234
{n,m}Between n and m times\d{2,4}12, 123, 1234
*?0 or more (lazy)<.*?><b> in <b>text</b>
+?1 or more (lazy)a+?a in aaa
PatternDescriptionExampleMatch
(...)Capturing group(ab)+ab, abab
(?:...)Non-capturing group(?:ab)+ab, abab
(?=...)Positive lookahead\d(?=px)3 in 3px
(?!...)Negative lookahead\d(?!px)3 in 3em
(?<=...)Positive lookbehind(?<=\$)\d+100 in $100
(?<!...)Negative lookbehind(?<!\$)\d+100 in 100
\1Back-reference to group 1(\w+)\s\1the the
$1Replacement reference to group 1s/(a)/[$1]/[a]
PatternDescriptionExampleMatch
gGlobal — find all matches/a/gall a's in string
iCase-insensitive matching/hello/iHello, HELLO
mMultiline — ^ and $ match line boundaries/^a/ma at line start
sDotall — . matches newlines/a.b/sa\nb
uUnicode — full Unicode support/\u{61}/ua
ySticky — match from lastIndex only/a/ya at lastIndex
PatternDescriptionExampleMatch
[\w.+-]+@[\w-]+\.[\w.]+Email addressuser@example.comuser@example.com
https?://[\w\-._~:/?#\[\]@!$&'()*+,;=%]+URLhttps://example.comhttps://example.com
\+?[\d\s\-().]{7,15}Phone number (international)+1 (555) 123-4567+1 (555) 123-4567
\b\d{1,3}(\.\d{1,3}){3}\bIPv4 address192.168.1.1192.168.1.1
\d{4}-\d{2}-\d{2}Date (YYYY-MM-DD)2024-01-152024-01-15
#([0-9a-fA-F]{3}){1,2}\bHex color code#ff6600, #f60#ff6600
<([a-z]+)[^>]*>.*?</\1>HTML tag (simple)<div>text</div><div>text</div>
\b\d{4}[\s-]?\d{4}[\s-]?\d{4}[\s-]?\d{4}\bCredit card number1234 5678 9012 34561234 5678 9012 3456

How to use Regex Cheatsheet

  1. 1. Browse sections. Scroll through character classes, anchors, quantifiers, groups, flags, and common patterns.
  2. 2. Search for a pattern. Use the filter box at the top to quickly find the regex syntax you need.
  3. 3. Copy a pattern. Click the copy button next to any entry to copy the pattern to your clipboard.

FAQ

What regex flavor does this cover?

This cheatsheet covers JavaScript/ECMAScript regex syntax, which is widely compatible with other languages including Python, Java, and C#.

What is the difference between greedy and lazy quantifiers?

Greedy quantifiers (*, +) match as much as possible. Lazy quantifiers (*?, +?) match as little as possible. Use lazy when you want the shortest match.

What are lookaheads and lookbehinds?

Lookahead (?=...) and lookbehind (?<=...) assert that a pattern exists ahead or behind the current position without including it in the match. Negative versions (?!...) and (?<!...) assert absence.

Related tools

Advertisement