Regex Tester

Test regular expressions with real-time match highlighting, group capture, and a built-in cheat sheet.

Real-time Match groups Cheat sheet Free
/ /
g global i insensitive m multiline s dotall
Enter a pattern above
Advertisement
Quick reference — click to insert

Regular Expressions — How They Work and When to Use Them

A regular expression (regex) is a pattern that describes a set of strings. Instead of checking if a string equals exactly "hello", you can check if it matches a pattern — starts with a capital letter, contains digits, is a valid email format. Regex is one of the most powerful text processing tools available across every programming language.

Anatomy of a regex pattern

The pattern ^[A-Z][a-z]+ \d{4}$ reads: start of string, one uppercase letter, one or more lowercase letters, a space, exactly four digits, end of string. This matches "Alice 1990" but not "alice 1990" or "Alice 99". Each piece has a meaning: ^ and $ are anchors, [A-Z] is a character class, + and {4} are quantifiers.

Flags change how matching works

The g flag finds all matches instead of just the first. The i flag makes matching case-insensitive — hello matches "Hello", "HELLO", and "hElLo". The m flag makes ^ and $ match the start and end of each line instead of the whole string. The s flag makes the dot (.) match newline characters.

The most common regex patterns

Email validation: [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}. URL matching: https?://[^\s]+. Phone numbers: \+?[\d\s\-()]{10,}. ISO dates: \d{4}-\d{2}-\d{2}. These are starting points — real-world validation often requires more nuance. Use the tester above to refine patterns against your actual data.

Frequently asked questions

What regex flavor does this use?
This tool uses JavaScript's built-in RegExp engine. It supports most standard regex syntax — character classes, quantifiers, anchors, groups, lookaheads — but not some features found in PCRE (Python/PHP), like named backreferences in all positions or atomic groups.
What do the flags mean?
g (global) — find all matches, not just the first. i (insensitive) — case-insensitive matching. m (multiline) — ^ matches start of each line, $ matches end. s (dotAll) — the . character matches newlines too.
How do I capture groups?
Wrap part of your pattern in parentheses: (\d{4})-(\d{2})-(\d{2}) captures year, month, day separately. Named groups use (?<name>...) syntax: (?<year>\d{4}). The match details panel shows all captured groups.
What is a lookahead in regex?
Lookaheads match a position based on what follows without consuming characters. foo(?=bar) matches "foo" only if followed by "bar". Negative lookahead foo(?!bar) matches "foo" NOT followed by "bar". Lookbehind uses (?<=...).
How do I match a literal dot or special character?
Escape it with a backslash: \. matches a literal dot (not any character). Special characters that need escaping: . * + ? ^ $ { } [ ] | ( ) \. To match a backslash itself: \\.
What is the difference between greedy and lazy quantifiers?
Greedy quantifiers (*, +, ?) match as much as possible. Lazy versions (*?, +?, ??) match as little as possible. Example: given <b>text</b>, <.*> greedy matches the whole string; <.*?> lazy matches just <b>.