Regex Tester - Test Regular Expressions Online

Test and debug regular expressions online. Free regex tester with live match highlighting, capture groups, flags, and match list. No signup needed.

🔒 Your text stays in your browser - nothing is sent to our servers
//g
Flags:Global
How to Use

Three steps to get started

1

Enter a regex pattern

Type your regular expression in the pattern field. The /pattern/flags notation is shown - enter only the pattern itself, then toggle flags below.

2

Paste your test string

Enter the text you want to test against in the test string area. Matches are highlighted in real time as you type.

3

Review matches and replace

Check the match count, highlighted positions, and captured groups. Expand the Replace section to test a substitution.

About This Tool

Regular expressions: essential and often mysterious

A regular expression is a compact string that describes a pattern of text, which an engine then uses to find, validate, extract, or replace matching substrings. The idea predates computing hardware: Stephen Kleene formalised regular sets in 1951, Ken Thompson built the first practical matcher into the QED editor in 1968, and the syntax spread through grep, sed, andawk into essentially every language and editor in use today.

This tester runs JavaScript's native RegExp, so what you see here is exactly what will happen in Node, Deno, and the browser. That matters because regex dialects genuinely differ. ECMAScript supports lookbehind ((?<=...), shipped in ES2018 and now in every current engine) and named groups, but it has no possessive quantifiers, no atomic groups, no recursion, and no \A or \z anchors - all of which exist in PCRE, the flavour behind PHP, Perl, and many Python examples you will find online. Patterns copied from a Perl answer often fail in JavaScript for precisely this reason.

Testing interactively matters because regex failures are usually silent. A misplaced quantifier does not throw; it just matches the wrong thing. The two errors that account for most of them are greediness - <.+> swallows an entire line of HTML where <.+?> stops at the first closing bracket - and missing anchors, since \d{5} without ^ and $ happily matches the first five digits of a twelve-digit string. Watching the highlights move as you type surfaces both immediately.

Quick regex cheat sheet

  • [A-Za-z0-9] - alphanumeric character
  • ^\d+$ - entire string is digits only
  • \b\w+\b - whole words
  • (?i) - case insensitive (use the i flag instead in this tester)
  • https?://\S+ - match URLs
  • (\d{1,3}\.){3}\d{1,3} - IPv4 address
  • ^.{0,160}$ - strings up to 160 characters

Two traps worth naming

Catastrophic backtracking. Nested quantifiers over overlapping character sets, the classic being (a+)+$, can force the engine to explore an exponential number of paths before conceding a failure. A pattern that runs in microseconds on short input can hang a server for minutes on a 40-character string - the ReDoS vulnerability class, responsible for outages including Cloudflare's 2019 global incident. If a pattern feels slow here on modest input, that is the warning sign; rewrite it to make each alternative match a disjoint set of characters.

Unicode and \w. Without the u flag, a regex operates on UTF-16 code units, so . matches only half of an emoji and \w is defined as exactly [A-Za-z0-9_] - accented letters like é and all non-Latin scripts are excluded. Validating names or addresses with \w quietly rejects a large share of the world's users. Prefer Unicode property escapes such as \p{L} with the u flag when the input is human text.

All matching, group capture, and replacement preview run in your browser through the JavaScript RegExp engine. No pattern and no test string is sent to a server, so you can debug against real log lines or production data safely.

FAQ

Frequently Asked Questions

Related Tools