Flowfiles ← Regex Tester

Regex Cheat Sheet

JavaScript regular expressions quick reference — character classes, quantifiers, groups, flags, assertions

A concise reference for JavaScript (RegExp) regular expressions. All syntax is tested against the V8 engine running in your browser.

Open the Regex Tester to try any pattern →

Flags

FlagNameEffect
gGlobalFind all matches, not just the first
iCase-insensitiveMatch uppercase and lowercase equally
mMultiline^ and $ match start/end of each line
sDotAll. matches newline characters too
uUnicodeEnable full Unicode support and strict escaping
dIndicesAdd indices array with start/end positions of each group

Character classes

SyntaxMatches
.Any character except newline (use s flag to include \n)
\dDigit [0-9]
\DNon-digit
\wWord character [a-zA-Z0-9_]
\WNon-word character
\sWhitespace (space, tab, newline, carriage return…)
\SNon-whitespace
[abc]Any of a, b, c
[^abc]Any character except a, b, c
[a-z]Any lowercase letter
[a-zA-Z0-9]Letter or digit

Anchors

SyntaxMatches
^Start of string (or line with m flag)
$End of string (or line with m flag)
\bWord boundary
\BNon-word boundary

Quantifiers

SyntaxMeaning
*0 or more (greedy)
+1 or more (greedy)
?0 or 1 (optional)
{n}Exactly n times
{n,}At least n times
{n,m}Between n and m times
*? +? ??Lazy (non-greedy) versions — match as few chars as possible

Groups & assertions

SyntaxMeaning
(abc)Capturing group — accessible as $1, match[1]
(?:abc)Non-capturing group — groups without capturing
(?<name>abc)Named capture group — accessible as match.groups.name
(?=abc)Positive lookahead — position followed by "abc"
(?!abc)Negative lookahead — position NOT followed by "abc"
(?<=abc)Positive lookbehind — position preceded by "abc"
(?<!abc)Negative lookbehind — position NOT preceded by "abc"
a|bAlternation — matches a or b

Common patterns

Use casePattern
Email[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}
URLhttps?://[^\s/$.?#].[^\s]*
ISO date\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])
IPv4\b(?:\d{1,3}\.){3}\d{1,3}\b
Hex color#(?:[0-9a-fA-F]{3}){1,2}\b
Semantic version\d+\.\d+\.\d+(?:-[a-zA-Z0-9.]+)?

Related tools