Regex Tester - Test Regular Expressions

Test and debug regular expressions in real time. Enter a pattern and test string to see matches highlighted with capture group details.

Regular Expression Quick Reference

Regular expressions (regex) are patterns that describe sets of strings. They are supported in virtually every programming language and are invaluable for input validation, parsing, search-and-replace, and data extraction.

Character Classes

PatternMatches
.Any character except newline
\dAny digit (0–9)
\DAny non-digit
\wWord character (a-z, A-Z, 0-9, _)
\WNon-word character
\sWhitespace (space, tab, newline)
\SNon-whitespace
[abc]One of a, b, or c
[^abc]Anything except a, b, or c
[a-z]Lowercase letter a through z

Quantifiers

PatternMeaning
*Zero or more (greedy)
+One or more (greedy)
?Zero or one (greedy)
*?Zero or more (lazy)
+?One or more (lazy)
{n}Exactly n times
{n,m}Between n and m times

Anchors and Groups

PatternMeaning
^Start of string (or line in multiline mode)
$End of string (or line in multiline mode)
\bWord boundary
(abc)Capturing group
(?:abc)Non-capturing group
(?<name>abc)Named capturing group
a|bAlternation — matches a or b

Common Regex Patterns

Regex in Popular Languages

JavaScript

const pattern = /(\d{4})-(\d{2})-(\d{2})/g;
const matches = [...text.matchAll(pattern)];
// Named groups: /(?<year>\d{4})-(?<month>\d{2})/

Python

import re
pattern = re.compile(r'(\d{4})-(\d{2})-(\d{2})')
match = pattern.search(text)
if match:
    year, month, day = match.groups()

Tips for Writing Better Regex

Frequently Asked Questions

What regex flags are supported?

Common flags: g (global — find all matches), i (case-insensitive), m (multiline — ^ and $ match line boundaries), s (dotAll — dot matches newlines), and u (Unicode mode). Flags can be combined, e.g. /pattern/gi.

How do I match a literal dot, parenthesis, or other special character?

Escape special regex characters with a backslash: \. matches a literal dot, \( matches a literal parenthesis. The characters requiring escaping are: . * + ? ^ $ { } [ ] | ( ) \

What is the difference between greedy and lazy matching?

Greedy quantifiers (*, +) match as much text as possible. Lazy quantifiers (*?, +?) match as little as possible. For <.+> on <a><b>, greedy matches the whole string; lazy <.+?> matches <a> and <b> separately.

Related Generate Tools