DevDash

Regex Tester

Test regular expressions with real-time matching and highlights.

Enter a pattern and test string to see matches highlighted instantly with position details.

//
gFind all matches, not just the first
iMatch regardless of upper/lowercase
m^ and $ match line starts and ends
sDot (.) also matches newline characters
Matches Highlighted2 matches
The quick brown fox jumps over the lazy dog. Contact us at support@example.com or sales@example.com. Phone: 555-123-4567 or (555) 987-6543.
Match Details
#MatchPositionGroups
1support@example.com59--
2sales@example.com82--

About Regular Expressions

A regular expression (regex or regexp) is a compact pattern language used to search, match, and transform text. Originally developed in the 1950s by mathematician Stephen Kleene and later popularized by Unix tools like grep and sed, regex has become an essential skill for developers, data analysts, and system administrators. Every mainstream programming language ships with a regex engine, and most code editors support regex-based find-and-replace.

Core Syntax

Regex patterns are built from literal characters and special metacharacters. A dot (.) matches any single character, a caret (^) anchors to the start of a line, and a dollar sign ($) anchors to the end. Character classes like [a-z] match any character in a range, while shorthand classes like \d (digits), \w (word characters), and \s (whitespace) cover the most common categories. Negated classes such as \D match everything the lowercase version does not.

Quantifiers and Flags

Quantifiers control how many times an element must appear. * means zero or more, + means one or more, ? means zero or one, and {n,m} specifies an exact range. By default, quantifiers are greedy — they consume as much text as possible. Appending ? makes them lazy, matching the shortest possible substring. Flags modify the overall behavior of the pattern: g finds all matches, i ignores case, m enables multiline mode, and s lets . match newlines.

Capture Groups and Common Patterns

Parentheses create capture groups that extract substrings from a match. Named groups like (?<year>\d{4}) make patterns self-documenting and easier to maintain. Non-capturing groups (?:...) group elements without storing the match. Common real-world patterns include email validation ([\w.+-]+@[\w-]+\.[\w.]+), URL detection, IP address matching, and date parsing. While these patterns are useful starting points, production systems should pair regex with dedicated parsing libraries for edge cases.

Testing Interactively

Building regex in your head is error-prone. An interactive tester like this one lets you see matches highlighted in real time, inspect capture groups, and iterate on your pattern before committing it to code. Once you're satisfied, copy the pattern into your codebase and write unit tests to lock in the expected behavior. Combining interactive testing with automated tests is the fastest path to reliable pattern matching.

Frequently Asked Questions

What is a regular expression?

A regular expression is a pattern syntax for matching text. Developers use regex for validation, searching, and extracting data from strings. Patterns range from simple literal matches to complex expressions with quantifiers, character classes, and lookaheads that can parse structured text in a single pass.

What does the g flag mean in regex?

The g (global) flag tells the regex engine to find all occurrences of the pattern in the input string, not just the first one. Without it, the engine stops after the first match. This flag is essential when you need to replace or extract every instance of a pattern throughout your text.

How do I match an email address with regex?

A common pattern like [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,} covers most cases, but edge cases in the RFC spec make a perfect email regex impractical. For production use, validate the format loosely with regex and confirm deliverability by sending a verification email.

What is the difference between greedy and lazy matching?

Greedy quantifiers (*, +, {n,}) match as much text as possible, while lazy quantifiers (*?, +?, {n,}?) match as little as possible. For example, given "<b>one</b><b>two</b>", a greedy <b>.*</b> matches the entire string, but <b>.*?</b> matches only the first tag pair.

What are capture groups in regex?

Capture groups use parentheses () to extract matched substrings for later use. Each group is numbered by its opening parenthesis. They let you pull specific pieces out of a match — like extracting the domain from a URL — and reference them in replacements or code via backreferences like \1 or $1.