Regex Tester

Test and debug regular expressions in real time. See matches highlighted, capture groups listed, and index positions for every match. Free, private, and runs entirely in your browser.

Ad Space — 728x90
Regular Expression
/ /
Test String
PatternDescriptionExample
.Any character (except newline)a.c matches "abc", "a1c"
\dDigit (0-9)\d{3} matches "123"
\DNon-digit\D+ matches "abc"
\wWord character (a-z, A-Z, 0-9, _)\w+ matches "hello_42"
\WNon-word character\W matches "@", " "
\sWhitespace (space, tab, newline)\s+ matches spaces
\SNon-whitespace\S+ matches "word"
^Start of string / line^Hello matches line start
$End of string / lineend$ matches line end
\bWord boundary\bword\b whole word only
[abc]Character class (a, b, or c)[aeiou] matches vowels
[^abc]Negated class (not a, b, or c)[^0-9] non-digits
a|bAlternation (a or b)cat|dog matches either
(abc)Capture group(\w+)@(\w+) captures parts
(?:abc)Non-capturing group(?:http|https)://
a*Zero or morego*gle matches "ggle", "gogle"
a+One or morego+gle matches "gogle", "google"
a?Zero or one (optional)colou?r matches both
a{3}Exactly n times\d{4} matches "2024"
a{2,5}Between n and m times\w{2,5} matches 2-5 chars
a*?Lazy (non-greedy) quantifier<.+?> shortest match
(?=abc)Positive lookahead\d(?=px) digit before "px"
(?!abc)Negative lookahead\d(?!px) digit not before "px"
Ad Space — 728x90

Free Online Regex Tester & Debugger

Regular expressions are one of the most powerful tools in a developer's toolkit, but they can also be one of the most confusing. SmarterSources' Regex Tester lets you write, test, and debug regular expressions in real time with instant visual feedback. See every match highlighted in your test string, view capture groups, and check index positions — all without leaving your browser.

How It Works

Type your regular expression in the pattern field and enter a test string below it. The tool instantly evaluates your regex against the test string on every keystroke. Matches are highlighted with a yellow background in the output area, and each match is listed with its position, full text, and any captured groups. If your pattern has a syntax error, a clear error message appears immediately.

Understanding Regex Flags

Flags modify how the regex engine interprets your pattern. The global (g) flag finds all matches instead of stopping at the first one. Case-insensitive (i) ignores uppercase and lowercase differences. Multiline (m) makes ^ and $ match the start and end of each line rather than just the entire string. DotAll (s) makes the dot (.) match newline characters, which it normally skips.

Working with Capture Groups

Parentheses in your regex create capture groups that extract specific parts of a match. For example, the pattern (\d{3})-(\d{3})-(\d{4}) matching a phone number like "555-123-4567" creates three groups: "555", "123", and "4567". This tool displays each group alongside its match, making it easy to verify your extraction logic.

Common Regex Patterns

Some frequently used patterns include: \b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b for email addresses, https?://[^\s]+ for URLs, ^\d{3}-\d{3}-\d{4}$ for US phone numbers, and ^\d{4}-\d{2}-\d{2}$ for ISO dates. Use the quick reference panel below the tool for a handy cheat sheet of regex syntax.

Tips for Writing Better Regex

Start simple and build up complexity gradually. Use non-greedy quantifiers (*?, +?) when you want the shortest possible match. Anchor your patterns with ^ and $ when validating full strings. Use character classes ([A-Z]) instead of alternation (A|B|C|...) when matching single characters. And always test with edge cases — empty strings, special characters, and unexpected input.

Frequently Asked Questions

What is a regular expression?

A regular expression (regex or regexp) is a sequence of characters that defines a search pattern. Regular expressions are used for pattern matching within strings, enabling tasks like validation, search-and-replace, and data extraction. They are supported in virtually every programming language including JavaScript, Python, Java, C#, PHP, and Ruby.

What do the regex flags g, i, m, and s mean?

The g (global) flag finds all matches in the string instead of stopping at the first. The i (case-insensitive) flag ignores letter casing when matching. The m (multiline) flag makes ^ and $ match the start and end of each line. The s (dotAll) flag makes . match newline characters as well.

Why is my regex not matching anything?

Common reasons include: forgetting the global flag so only the first match is found, not escaping special regex characters (like ., (, ), [) with a backslash, using incorrect character classes, or case sensitivity when the i flag is not set. Make sure special characters that should be literal are escaped with a backslash.

What are capture groups?

Capture groups are portions of a regex enclosed in parentheses (). They "capture" the text matched by that part of the pattern, letting you extract or reference it later. For example, (\d{3})-(\d{4}) matching "555-1234" captures "555" as group 1 and "1234" as group 2. Use (?:...) for non-capturing groups when you need grouping without capture.

Is my data safe?

Yes. All regex processing happens entirely in your browser using JavaScript. Your patterns and test strings never leave your device. SmarterSources does not collect, store, or transmit any data you enter into this tool.

Can this tool handle complex regex patterns?

Yes. This tool uses JavaScript's native RegExp engine, which supports most modern regex features including lookaheads, lookbehinds (in supported browsers), named groups, non-greedy quantifiers, and Unicode character classes. Performance depends on your browser and the complexity of the pattern, but it handles most real-world patterns instantly.