Regex Tester — Test Regular Expressions Online

This regex tester lets you write, test, and debug regular expressions in real time. Enter a pattern and test string to see matches highlighted instantly, with detailed capture group extraction, named group support, and find-and-replace functionality. Browse common regex templates or toggle flags to customize matching behavior.

Regex Tester

Test and debug regular expressions in real time with match highlighting and capture group details

//g

Frequently Asked Questions

What is a regular expression (regex)?

A regular expression (regex or regexp) is a sequence of characters that defines a search pattern. It is used for pattern matching within strings — finding text that matches a specific structure, validating input formats, and performing search-and-replace operations. Regex is supported in virtually every programming language including JavaScript, Python, Java, Go, and many text editors.

What are the most common regex patterns?

The most commonly used regex patterns include: email validation ([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}), URL matching (https?://[\w.-]+), phone numbers (\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}), IP addresses, dates in ISO format (\d{4}-\d{2}-\d{2}), hex color codes (#[0-9a-fA-F]{3,6}), and integer or decimal number matching.

What are capture groups in regex?

Capture groups are portions of a regex pattern enclosed in parentheses ( ). When the regex matches, each group captures the text it matched, which can be referenced later. For example, (\d{4})-(\d{2})-(\d{2}) matching '2026-03-22' creates three capture groups: $1='2026', $2='03', $3='22'. Named groups use the syntax (?<name>...) for clearer code. Non-capturing groups (?:...) group without capturing.

What are lookahead and lookbehind assertions?

Lookahead and lookbehind are zero-width assertions that check for patterns without including them in the match. Positive lookahead (?=abc) matches a position followed by 'abc'. Negative lookahead (?!abc) matches a position not followed by 'abc'. Positive lookbehind (?<=abc) matches a position preceded by 'abc'. Negative lookbehind (?<!abc) matches a position not preceded by 'abc'. They are useful for complex conditional matching.

What is the difference between greedy and lazy matching?

Greedy quantifiers (*, +, ?) match as much text as possible, while lazy quantifiers (*?, +?, ??) match as little as possible. For example, given the string '<b>bold</b>', the greedy pattern <.*> matches the entire string '<b>bold</b>', but the lazy pattern <.*?> matches only '<b>'. Use lazy quantifiers when you want the shortest possible match.

What is catastrophic backtracking in regex?

Catastrophic backtracking occurs when a regex engine takes exponential time to determine that a string does not match a pattern. This happens with nested quantifiers like (a+)+ or patterns with overlapping alternatives. The engine tries every possible combination before failing, causing extreme slowness or freezing. Avoid this by using specific character classes, atomic groups, and limiting repetition bounds.

What do regex flags (modifiers) do?

Regex flags modify how the pattern is interpreted. Common flags include: g (global) — find all matches instead of just the first; i (case insensitive) — ignore uppercase/lowercase differences; m (multiline) — ^ and $ match line boundaries instead of string boundaries; s (dotall) — the . character matches newlines; u (unicode) — enable full Unicode matching. Flags can be combined, e.g., /pattern/gim.

How do I test a regex online?

Enter your regex pattern in the pattern field and paste your test string in the text area below. Matches are highlighted in real time as you type. Toggle flags (g, i, m, s, u) using the flag buttons. View match details including index positions and capture groups in the match panel. Use the replace section to test substitution patterns, and browse common templates for pre-built patterns.

How does regex replace work with backreferences?

In regex replacement, backreferences let you reuse captured groups in the replacement string. Use $1, $2, etc. to refer to numbered capture groups, or $<name> for named groups. For example, replacing (\w+)\s(\w+) with $2 $1 swaps two words. In the replacement string, $& refers to the entire match, $` to text before the match, and $' to text after the match.

What is the difference between regex and glob patterns?

Glob patterns are simpler wildcard patterns used mainly for file path matching in shells (e.g., *.txt, src/**/*.js). They support * (any characters), ? (single character), and [...] (character class). Regex is far more powerful, supporting quantifiers, anchors, groups, alternation, lookaround, and backreferences. Regex operates on any string content, while globs are typically limited to path matching.

About Regular Expressions

Regular expressions (regex) are powerful patterns used to match, search, and manipulate text. They form a concise language for describing character sequences: from simple literal matches to complex patterns involving repetition, alternation, grouping, and lookaround assertions. Regex is supported in virtually every programming language and text editor, making it an essential tool for developers, data analysts, and system administrators.

This regex tester lets you write, test, and debug regular expressions in real time. As you type your pattern and test string, matches are highlighted instantly, capture groups are extracted, and execution time is measured. You can also perform find-and-replace operations using backreferences.

Regex Syntax Quick Reference

Character Classes

PatternDescription
[abc]Match any one of a, b, or c
[^abc]Match any character except a, b, or c
[a-z]Match any character in the range a to z
\dMatch any digit (equivalent to [0-9])
\DMatch any non-digit
\wMatch any word character (letters, digits, underscore)
\WMatch any non-word character
\sMatch any whitespace character (space, tab, newline)
\SMatch any non-whitespace character
.Match any character except newline (unless s flag is set)

Quantifiers

PatternDescription
*Match 0 or more times (greedy)
+Match 1 or more times (greedy)
?Match 0 or 1 time (greedy)
{n}Match exactly n times
{n,}Match n or more times
{n,m}Match between n and m times
*?Match 0 or more times (lazy / non-greedy)
+?Match 1 or more times (lazy / non-greedy)

Anchors

PatternDescription
^Match start of string (or line with m flag)
$Match end of string (or line with m flag)
\bMatch word boundary
\BMatch non-word boundary

Groups & Lookaround

PatternDescription
(abc)Capture group — matches "abc" and stores the result
(?:abc)Non-capturing group — groups without storing
(?<name>abc)Named capture group
\1Backreference to capture group 1
a|bAlternation — match a or b
(?=abc)Positive lookahead — matches if followed by "abc"
(?!abc)Negative lookahead — matches if not followed by "abc"
(?<=abc)Positive lookbehind — matches if preceded by "abc"
(?<!abc)Negative lookbehind — matches if not preceded by "abc"

Common Regex Patterns

Here are regex patterns frequently used in real-world applications:

  • Email validation[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,} matches standard email addresses
  • URL matchinghttps?://[\w.-]+(?:\.[\w.-]+)+[\w.,@?^=%&:/~+#-]* matches HTTP and HTTPS URLs
  • IP address\b(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\b validates IPv4 addresses
  • Date (ISO)\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01]) matches YYYY-MM-DD dates
  • Hex color#(?:[0-9a-fA-F]{3}){1,2}\b matches #RGB and #RRGGBB color codes
  • Password strength^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,} requires uppercase, lowercase, digit, and special character (8+ chars)

Regex in Different Languages

While the core regex syntax is broadly similar across languages, there are notable differences in features, escaping rules, and API usage:

FeatureJavaScriptPythonJavaGo
EngineV8/SpiderMonkeyre modulejava.util.regexRE2
LookaroundYesYesYesNo
Named groups(?<name>...)(?P<name>...)(?<name>...)(?P<name>...)
Backreference\1 or $1\1 or \g<1>\1 or $1Not supported
BacktrackingYesYesYesNo (RE2 is linear)
Example/\d+/g.test(s)re.findall(r'\d+', s)Pattern.compile("\\d+")regexp.MustCompile(`\d+`)

Regex Performance Tips

Poorly written regex patterns can cause catastrophic backtracking, where the engine takes exponential time to process certain inputs. Follow these tips to write efficient patterns:

  • Avoid nested quantifiers — Patterns like (a+)+ or (a*)* cause exponential backtracking on non-matching inputs. Simplify to a+
  • Use atomic groups or possessive quantifiers — Where supported, (?>...) prevents the engine from backtracking into a group
  • Be specific with character classes — Use [a-z] instead of . when you know which characters to expect. Narrower classes reduce unnecessary matching attempts
  • Anchor your patterns — Add ^ and $ anchors when matching complete strings to prevent the engine from trying every position
  • Prefer non-greedy quantifiers when appropriate.*? stops at the first match rather than consuming the entire string and backtracking
  • Limit repetition bounds — Use {1,100} instead of + to cap the number of iterations and prevent runaway matching
  • Test with adversarial inputs — Always test your regex with long strings of nearly-matching text to identify potential backtracking issues before deploying to production

Related Tools

  • Case Converter — Convert text between UPPER, lower, Title, camelCase, and more
  • Word Counter — Count words, characters, sentences, and paragraphs in your text
  • URL Encoder & Decoder — Percent-encode and decode URLs for web applications

Related Tools