/regex

Regex Tester & Highlighter (JavaScript/ES6)

Test and debug regular expressions (regex) live with syntax highlighting and match groups.

/ /
  • g, global, find all matches, not just the first
  • i, case-insensitive
  • m, multiline, ^ and $ match start/end of each line
  • s, dotall, . also matches newlines
  • u, unicode, treat the pattern as unicode
Highlights 0
Regex cheat sheet
. any single character
\ escape, literal special char
a|b a or b
^ / $ start / end of text (or line with m)
\w / \W word char (a-z, 0-9, _) / non-word
\d / \D digit / non-digit
\s / \S whitespace / non-whitespace
\b word boundary
* Repeats the previous token 0 or more times
+ Repeats the previous token 1 or more times
? The previous token is optional (0 or 1 time)
{n} / {n,m} exactly n / between n and m
[abc] character range
(...) capture group
(?:...) non-capturing group

How it works

A regular expression (regex) is a search pattern describing the text you are looking for. Type the pattern in the top field and your text below, matches are highlighted live as you type, and the match count is shown.

Flags

The flags to the right of the pattern change how the search behaves. “g” (global) is on by default and is needed to find more than one match. “i” makes the search case-insensitive.

Groups

Parentheses () create capture groups, the parts of a match you want to extract separately. They appear in the “Groups in first match” table as $1, $2, and so on. Use (?<name>…) for named groups.

Tip: Click an example above to get started quickly, and open the cheat sheet for an overview of the most common tokens. Everything runs locally in your browser.

About this tool

Regular expressions (regex) are a compact pattern language that lets you search, match and replace text based on structural rules instead of exact strings. A single line of regex can do the job of hundreds of `if` statements, but the syntax is dense and errors are often cryptic. This tool lets you write a pattern, see matches highlighted in your text in real time, toggle flags (`g`, `i`, `m`, `s`, `u`) and test replacement patterns with capture groups. Everything runs with JavaScript’s built-in regex engine locally in the browser.

How to use it

  1. Write your regex pattern in the pattern field (no slashes around it).
  2. Choose flags, `g` for all matches, `i` for case-insensitive, `m` for multi-line, `s` for `.` matching newline.
  3. Paste the text you want to search, and see matches highlighted immediately.
  4. For replacement: write the replacement string using `$1`, `$2` etc. for capture groups.
  5. On a syntax error, the JavaScript engine’s error message is shown below the pattern field.

Examples

Match email addresses
Input[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}
A simple "good enough" email regex. A 100 % correct one is actually over 6,000 characters long (see RFC 5322).
Replace with capture groups
Input(\d{4})-(\d{2})-(\d{2})
Output$3.$2.$1
Converts "2026-07-05" to "05.07.2026". Parenthesised groups are captured and referenced in the replacement as `$1`, `$2`, `$3`.
Whole-word match
Input\bcat\b
`\b` is a "word boundary", matches "cat" but not "cats", "scat" or "concatenation".

Common use cases

  • Validating form input (postal codes, phone numbers, email) on the client side.
  • Extracting every URL, hashtag or version number from a document.
  • Bulk-renaming files or columns by matching a pattern and using capture groups.
  • Cleaning log files by stripping timestamps or IP addresses.
  • Converting text between formats (Markdown links, CSV columns, date representations).
  • Verifying a string follows a specific format before passing it downstream.

Frequently asked questions

Why does my "greedy" pattern match too much?
Quantifiers `*`, `+` and `?` are greedy by default, they consume as much as possible. Add `?` after (like `.*?`) for lazy matching that stops at the first possible match.
Can I parse HTML with regex?
No, at least not reliably. HTML is not a regular language, so no regex can correctly handle nested tags, comments and CDATA. Use a DOM parser (`DOMParser` in the browser) instead. Regex is fine for simple extraction from known, controlled HTML.
What is the difference between `.` and `[.]`?
`.` matches any single character (except newline unless the `s` flag is set). `[.]` is a character class matching only a literal dot. Use `[.]` (or `\.`) when you actually mean "dot".
What is "catastrophic backtracking"?
When a pattern can match the same text in many different ways (typically `(a+)+`), the engine can spend exponential time exploring all possibilities. This can lock up the browser or cause DoS attacks (ReDoS). Avoid nested quantifiers on overlapping patterns.

Technical background

JavaScript regex (the ECMAScript standard) is implemented as a backtracking NFA engine. It supports Unicode mode (`u` flag) and named capture groups (`(?<name>…)`). ES2018 added lookbehind (`(?<=…)`, `(?<!…)`) and the `s` flag (dotAll). The browser engine is very fast for simple patterns, but can be exponential worst-case for pathological patterns (see ReDoS). For safely validating user input in a backend, consider RE2-based engines (Go, Rust) which guarantee linear time.