// regular expression
/ /
// test string
Ready — enter a regex pattern and test string
// matches 0 matches
No matches yet — enter a pattern above

// character classes

.Any character except newline
\wWord character [a-zA-Z0-9_]
\dDigit [0-9]
\sWhitespace character
\WNon-word character
\DNon-digit character
[abc]Character set a, b, or c
[^abc]Not a, b, or c

// quantifiers

*0 or more
+1 or more
?0 or 1 (optional)
{n}Exactly n times
{n,}n or more times
{n,m}Between n and m times
*?Lazy (non-greedy)

// anchors & groups

^Start of string/line
$End of string/line
\bWord boundary
(abc)Capture group
(?:abc)Non-capture group
a|bMatch a or b
(?=abc)Positive lookahead

// what is a regular expression?

A regular expression (regex) is a sequence of characters that defines a search pattern. Regex is used in programming for string searching, validation, and text manipulation across virtually every language.

JavaScript regex uses the RegExp object or literal syntax /pattern/flags. See our full regex cheat sheet and guide to the best regex testers for JavaScript.

// regex flags explained

g (global) — finds all matches, not just the first one.

i (case insensitive) — matches regardless of uppercase or lowercase.

m (multiline) — makes ^ and $ match start/end of each line.

s (dotall) — makes . match newline characters too.

// frequently asked questions
How do I test a regex in JavaScript?
Use regex.test(string) to check if a pattern matches, or string.match(regex) to get the matches. For all matches use the g flag with string.matchAll(regex). See our guide: best regex testers for JavaScript.
What is a capture group in regex?
A capture group (pattern) lets you extract a specific part of a match. For example (\d{4})-(\d{2})-(\d{2}) matches a date and captures year, month, and day separately. Use (?:pattern) for a non-capturing group when you don't need the value. Full reference in our regex cheat sheet.
How do I match an email address with regex?
A basic email regex: [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}. Click "Load Sample" above to see it in action with test data. Note that perfectly validating all email formats with regex is complex — for production use, consider a dedicated validation library.
What is the difference between greedy and lazy matching?
Greedy quantifiers like .* match as much as possible. Lazy quantifiers like .*? match as little as possible. For example, given <b>text</b>, the greedy <.*> matches the whole string, while the lazy <.*?> matches just <b>.
How do I match a whole word in regex?
Use word boundaries: \bword\b. The \b anchor matches the position between a word character and a non-word character. For example \bcat\b matches "cat" but not "catch" or "concatenate".