DevFormatter

Regex Tester

/ /
 

Regex Tester is a free browser-based tool for testing JavaScript regular expressions against any string. It shows all matches with their start and end positions, numbered capture groups, and named capture groups instantly as you type. Supports the g, i, m, and s flags. All processing runs in the browser using the built-in RegExp engine — your pattern and test string never leave your machine.

Regex Tester

How it works

Last updated: November 2026

A regular expression (regex) is a pattern for matching, searching, and extracting text. Enter your pattern in the /pattern/ bar above the editor, type or paste your test string in the left panel, and click Test. The right panel shows every match with its position and any named capture groups.

Toggle the flags using the buttons next to the pattern: g (find all matches), i (case insensitive), m (multiline — ^ and $ match line boundaries), s (dotAll — . matches newlines).

This tester uses JavaScript's built-in RegExp engine. All processing runs in your browser — your pattern and test string are never sent to any server.

Regex Quick Reference

Character classes

\dAny digit [0–9]
\wWord char [a-zA-Z0-9_]
\sWhitespace (space, tab, newline)
.Any char except newline (unless s flag)
[abc]Character class — a, b, or c
[^abc]Negated class — not a, b, or c

Quantifiers

*0 or more (greedy)
+1 or more (greedy)
?0 or 1 (optional)
{n,m}Between n and m times
*?0 or more (lazy)
+?1 or more (lazy)

Anchors & boundaries

^Start of string (or line with m)
$End of string (or line with m)
\bWord boundary
\BNon-word boundary

Groups

(abc)Capture group
(?<name>abc)Named capture group
(?:abc)Non-capturing group
(?=abc)Positive lookahead
(?!abc)Negative lookahead
(?<=abc)Positive lookbehind (ES2018)

Tips & Tricks

Use raw strings to avoid double-escaping

In Python, prefix patterns with r: r'\d+' instead of '\\d+'. In JS, use a regex literal /\d+/ instead of new RegExp('\\\\d+'). Forgetting this is the most common source of regex bugs in code.

Named groups make patterns self-documenting

(?<year>\d{4})-(?<month>\d{2}) is far clearer than (\d{4})-(\d{2}) and doesn't break if you add a group earlier in the pattern. In Python use (?P<name>...) syntax instead.

Catastrophic backtracking can freeze your app

Patterns like (a+)+ or (.*)* cause exponential backtracking on certain inputs. Use atomic groups or possessive quantifiers (not supported in JS) if your regex must handle adversarial input. For validation, prefer purpose-built parsers over complex regex.

Use non-greedy quantifiers for HTML-like patterns

Greedy <.*> on <a><b> matches the entire string. Non-greedy <.*?> matches <a> and <b> separately. Add the ? whenever you want the shortest possible match.

\b matches at word edges, not between words

\bcat\b matches the whole word "cat" but not "catch", "cats", or "tomcat". The boundary is between a \w character and a \W character (or string start/end). Use \b to avoid partial matches in word searches.

The g flag resets lastIndex — always reset between uses

When using exec() in a loop with the g flag, the regex's lastIndex advances. If you reuse the same regex object on a new string without resetting, it starts searching from where it left off. Either reset with re.lastIndex = 0 or create a new RegExp each time.

Code Examples

Node.js / JavaScript

// Test a regex pattern
const pattern = /(?\d{4})-(?\d{2})-(?\d{2})/g;
const input = 'Release 2024-01-15, patch 2024-03-22';

let match;
while ((match = pattern.exec(input)) !== null) {
  console.log(match[0]);          // full match: "2024-01-15"
  console.log(match.groups.year); // named group: "2024"
  console.log(match.index);       // start position: 8
}

// One-liner for all matches (no groups)
const matches = input.match(/\d{4}-\d{2}-\d{2}/g);
// ["2024-01-15", "2024-03-22"]

Python

import re

pattern = r'(?P\d{4})-(?P\d{2})-(?P\d{2})'
text = 'Release 2024-01-15, patch 2024-03-22'

for m in re.finditer(pattern, text):
    print(m.group(0))           # full match
    print(m.group('year'))      # named group
    print(m.start(), m.end())   # positions

# All matches as a list
dates = re.findall(r'\d{4}-\d{2}-\d{2}', text)
# ['2024-01-15', '2024-03-22']

CLI

# grep with extended regex (-E) or Perl regex (-P)
echo "hello world" | grep -oE '\w+'
# hello
# world

# grep with named groups (Perl mode, macOS needs pcre2grep)
echo "2024-01-15" | grep -oP '(?P\d{4})-(?P\d{2})'

# sed: replace all matches
echo "foo bar foo" | sed 's/foo/baz/g'
# baz bar baz

# ripgrep: fast regex search in files
rg '\b\d{4}-\d{2}-\d{2}\b' ./logs/

Frequently Asked Questions

What is a regular expression?
A regular expression (regex or regexp) is a pattern that describes a set of strings using a compact, formal syntax. It is used to search, validate, extract, and replace text in a wide range of tasks: form validation (email, phone, postal code), log parsing, data extraction, and find-and-replace operations in code editors. For example, \d+ matches one or more digits, \w+ matches one or more word characters (letters, digits, underscore), [a-z]{3} matches exactly three lowercase letters, and ^\d{4}-\d{2}-\d{2}$ validates an ISO date string. Regular expressions are supported natively in virtually every programming language — JavaScript, Python, Java, Go, Ruby, PHP, Perl, C#, Rust — and in most text editors and command-line tools such as grep, sed, awk, and ripgrep. The syntax varies slightly across engines, but the core features are largely portable.
What regex engine does this tester use?
This tester uses JavaScript's built-in RegExp engine, which follows the ECMA-262 specification — the same engine used by all major JavaScript runtimes including V8 (Chrome, Node.js, Deno), SpiderMonkey (Firefox), and JavaScriptCore (Safari). It supports character classes, quantifiers, anchors, alternation, capture groups, non-capturing groups, lookahead ((?=...) and (?!...)), lookbehind ((?<=...) and (?<!...), added in ES2018), named capture groups ((?<name>...), also ES2018), and the g, i, m, s, u, and v flags. Patterns that work here will work directly in any modern JavaScript or TypeScript codebase. Note that JavaScript regex syntax differs slightly from Python's re module (which uses (?P<name>...) for named groups) and from PCRE (which supports atomic groups and possessive quantifiers that JavaScript does not).
What do the flags g, i, m, and s do?
The four most commonly used flags are: g (global) finds all matches in the string instead of stopping at the first one — without it, match() returns only the first match. i (case insensitive) makes character matching ignore letter case, so /hello/i matches "Hello", "HELLO", and "hello". m (multiline) changes the behaviour of ^ and $ so they match the start and end of each line in a multi-line string, rather than the start and end of the entire string — essential when processing log files or multi-line input. s (dotAll, added in ES2018) makes the dot (.) match every character including newline characters (\n and \r), which the dot does not match by default. Without the s flag, patterns like /.*/ fail on strings that span multiple lines. Flags can be combined: /pattern/gim finds all case-insensitive matches with multiline anchors.
How do named capture groups work?
Named capture groups use the syntax (?<name>pattern) in JavaScript (ES2018+). For example, (?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2}) captures an ISO date into three named groups. In JavaScript, access the captured values via match.groups.year, match.groups.month, and match.groups.day. With String.prototype.matchAll(), iterate all matches and access m.groups on each. Named groups also work in replacement strings: '2024-01-15'.replace(/(?<y>\d{4})-(?<m>\d{2})-(?<d>\d{2})/, '$<d>/$<m>/$<y>') produces '15/01/2024'. In Python, the equivalent syntax is (?P<name>...) and groups are accessed via m.group('year') or m.groupdict(). Named groups are supported in JavaScript (ES2018+), Python, .NET, Perl, Ruby, and PCRE — making patterns self-documenting and resilient to group reordering.
What is the difference between greedy and lazy quantifiers?
Greedy quantifiers (*, +, ?, {n,m}) instruct the engine to consume as many characters as possible while still allowing the overall pattern to match. Lazy (non-greedy) quantifiers (*?, +?, ??, {n,m}?) consume as few characters as possible. Given the string <a>text<b>, the greedy pattern <.*> matches the entire string from the first < to the last >, because .* greedily expands to include all characters including the inner >. The lazy pattern <.*?> matches <a> and then <b> as separate matches, because .*? stops at the earliest >. Use lazy quantifiers when parsing HTML-like markup or extracting values between delimiters. However, avoid using regex to parse real HTML — use a DOM parser instead, as regex cannot handle nested structures reliably.
Why does my regex work here but not in my code?
The most common causes of patterns working in a tester but failing in code are: (1) Backslash escaping — in string literals, backslashes must be doubled: '\d+' passes a literal string d+ to new RegExp(), not a digit pattern; use '\\d+' or a regex literal /\d+/. In Python, use raw strings: r'\d+' instead of '\\d+'. (2) Missing the g flag — without global, str.match(/pattern/) in JavaScript returns only the first match, not an array of all matches. (3) Different regex engine — JavaScript's ECMA-262 engine differs from Python's re module, PCRE (used by PHP and many tools), and .NET's regex. Features like possessive quantifiers (a++), atomic groups ((?>...)), and variable-length lookbehind exist in PCRE/.NET but not in JavaScript. (4) Anchoring — a pattern without ^/$ anchors matches anywhere in the string, which may differ from what you expect when validating an entire field value.
How do I match a literal dot or parenthesis?
Escape special regex characters with a backslash: \. matches a literal dot, \( and \) match literal parentheses, \* matches a literal asterisk, and so on. The complete set of regex metacharacters that must be escaped outside a character class is: . * + ? ^ $ { } [ ] | ( ) \. Inside a character class ([...]) most metacharacters lose their special meaning — only the closing bracket ], backslash \, caret ^ (at the start), and hyphen - (between characters) need escaping. A common pitfall is forgetting to escape the dot when writing patterns like example.com — without escaping, the dot matches any character, so example.com would also match exampleXcom. To programmatically escape a string for use in a RegExp constructor, use: str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&').
What is catastrophic backtracking?
Catastrophic backtracking (also called ReDoS — Regular Expression Denial of Service) occurs when a regex pattern has exponential worst-case complexity. Patterns like (a+)+, (a|aa)+, or (.*)* cause the engine to try an exponentially large number of ways to match the string before concluding there is no match. For example, testing (a+)+ against a string of 25 'a' characters followed by 'b' can cause the engine to take several seconds or freeze entirely. This is a real security risk in web applications that run user-supplied or dynamically constructed regex patterns. Prevention strategies: avoid nested quantifiers on overlapping character classes, use possessive quantifiers or atomic groups (available in PCRE but not JavaScript), or set a timeout using a worker thread. The safe-regex and recheck npm packages can statically analyse patterns for ReDoS vulnerability.
What is the difference between \d, \w, and \s?
\d matches any digit (0–9). \w matches any word character (letters, digits, underscore — equivalent to [a-zA-Z0-9_]). \s matches any whitespace character (space, tab, newline, carriage return). Their uppercase inverses match the opposite: \D matches non-digits, \W matches non-word characters, \S matches non-whitespace.
What is the difference between ^ and \b?
^ is a line anchor — it matches at the start of the string (or start of a line in multiline mode). \b is a word boundary — it matches at the position between a word character (\w) and a non-word character. Use ^ to match the beginning of a line, and \b to match whole words. For example, \bcat\b matches 'cat' but not 'catch' or 'tomcat'.
How do lookahead and lookbehind work?
Lookahead (?=...) asserts that what follows the current position matches the pattern, without consuming characters. Negative lookahead (?!...) asserts it does not match. Lookbehind (?<=...) asserts what precedes the position matches. Example: \d+(?= dollars) matches a number only if followed by ' dollars'. Lookbehind requires ES2018+ in JavaScript.
How do I test a regex in Python?
Use the re module: re.search(pattern, string) for the first match, re.findall(pattern, string) for all matches as a list, re.finditer(pattern, string) for match objects with position info. Python uses (?P<name>...) syntax for named groups (not (?<name>...) as in JavaScript). Prefix patterns with r to use raw strings: r'\d+' instead of '\\d+'.
Is my data sent to a server?
No. All regex testing runs entirely in your browser using JavaScript's built-in RegExp engine — your pattern and test string never leave your machine and no data is sent to any server. This matters because regex patterns used in production code and the strings they process often contain sensitive information: authentication tokens, PII, proprietary log formats, or internal API structures. Keeping all processing local means none of that data is ever exposed to a third-party service. You can verify this by opening your browser's Network tab in DevTools — no outbound requests are made when you type a pattern or test string. No account, login, or sign-up is required, and the tool works fully offline once the page has loaded. Tab state including your pattern, flags, and test string is saved to localStorage so it persists between sessions on the same browser, but never leaves your device.

Related Tools

Other free developer tools available on DevFormatter.