Tools

Free Online Regex Tester

Test and debug JavaScript regular expressions in your browser. See matches highlighted live, inspect capture groups, and preview replacements. Nothing is ever sent to a server.

Flags
Quick Patterns

Match Results

All matching happens locally in your browser. Your patterns and text are never uploaded, stored, or logged.

What is a Regular Expression?

A regular expression (regex) is a sequence of characters that defines a search pattern. Instead of looking for one fixed string, a regex describes the shape of the text you want — digits, words, email addresses, dates, and more. This makes pattern matching one of the most powerful tools for developers, data analysts, and sysadmins, who rely on it every day to validate input, search through logs, and transform text quickly and reliably.

JavaScript Regex Flags Explained

g global — find all matches in the string, not just the first one.
i case-insensitive — letters match regardless of upper or lower case.
m multiline — the anchors ^ and $ match the start and end of each line, not just the whole string.
s dotAll — the dot . also matches newline characters.
u unicode — enables full Unicode matching, including code points above U+FFFF.

Common Regex Patterns Reference

Pattern Regex Matches
Email /[^\s@]+@[^\s@]+\.[^\s@]+/ hello@charcount.app
URL /https?:\/\/[^\s]+/ https://charcount.app
IPv4 /\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/ 192.168.0.1
Date (YYYY-MM-DD) /\d{4}-\d{2}-\d{2}/ 2026-06-30
Hex Color /#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})\b/ #4338ca
UUID v4 /[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab]…/i 9f1c…5b6c

Regex Capture Groups

Parentheses let you capture parts of a match so you can extract or reuse them. There are three kinds:

  • ( ) — a capturing group: stores what it matched, accessible as $1, $2, … in replacements.
  • (?: ) — a non-capturing group: groups the pattern for alternation or quantifiers without storing it.
  • (?<name> ) — a named group: captures with a readable name, accessible as groups.name.

For example, parsing a date with three groups: (\d{4})-(\d{2})-(\d{2})

Frequently Asked Questions

.* is greedy: it matches as much text as possible, then backtracks if needed. .*? is lazy (non-greedy): it matches as little as possible and expands only when forced to. For example, against the text "<a><b>", the pattern <.*> matches the whole "<a><b>", while <.*?> matches just "<a>". Use the lazy version when you want the shortest possible match, such as parsing individual HTML tags.

Characters like . ( ) [ ] { } + * ? ^ $ | \ have special meaning in regex, so to match them literally you escape them with a backslash. Write \. for a literal dot, \( for a literal open parenthesis, and \\ for a literal backslash. Inside a character class, for example [.], most of these characters lose their special meaning and do not need escaping.

Most online testers default to the PCRE engine, while this tool and your browser use the JavaScript (ECMAScript) engine, which lacks some features. JavaScript does not support lookbehind in older engines, possessive quantifiers, recursion, or inline flags like (?i). Make sure your tester is set to the JavaScript flavor so the behaviour matches what your code will actually do.

The g (global) flag makes the regex find every match in the string instead of stopping at the first one. You need it when using methods like matchAll() or replaceAll(), or when replacing all occurrences with replace(). Without g, methods such as replace() only change the first match. Note that a global regex keeps a lastIndex state, so reuse it carefully when calling exec() in a loop.