Skip to content
WebTricks

Regex tester

Test a regular expression against text with live match highlighting and capture groups. Powered by the native engine.

Flags2 matches
Matches
Contact us at hi@webtricks.dev or support@example.com for help.

What this regex tester does

Type a pattern, toggle the flags, paste some text, and every match is highlighted in place with a running count. The tester uses the browser’s native JavaScript RegExp engine, not a reimplementation, so what you see is precisely what str.match(re), re.test(str) or str.replace(re, ...) will do in your JavaScript or TypeScript code. Syntax errors (an unclosed group, a bad quantifier, an invalid escape in u mode) show up immediately as the engine’s own error message instead of a silent zero-match result.

How to use it

  1. Enter the pattern body in the Pattern field, without surrounding slashes. The field turns red when the pattern does not compile and the engine’s error text appears below.
  2. Click the g i m s u buttons to toggle flags. Active flags are highlighted.
  3. Paste or type into Test text. Highlighting and the match count update on every keystroke.
  4. Read the Matches panel. Each highlighted span is one full match; overlapping matches are not possible in JavaScript, so each character belongs to at most one match.

Flags reference

FlagNameEffect
gglobalFind every match instead of stopping at the first. Changes match() to return all matches and replace() to replace all. Required by matchAll().
iignore casea matches A. With u it also applies Unicode case folding (so ſ matches s).
mmultiline^ and $ match at the start and end of every line, not just the whole string.
sdotAll. also matches \n and \r. Without it, a dot never crosses a line break.
uunicodeTreats the pattern as code points. Enables \p{...} property escapes and makes . match astral characters such as emoji as one unit. Also makes the engine strict about unnecessary escapes.
ystickyNot exposed in the UI. Matches only at lastIndex; mainly used when writing tokenizers.

Cheat sheet: patterns people search for

These are practical, readable versions rather than RFC-perfect ones. Use them as a starting point and test them against your own data.

GoalPatternNotes
Email (loose)[\w.+-]+@[\w-]+\.[\w.-]+Good for finding addresses in text. Use the browser’s type="email" for form validation instead.
URLhttps?:\/\/[^\s<>"']+Stops at whitespace and quotes; trailing punctuation may be included.
IPv4\b(?:(?:25[0-5]|2[0-4]\d|1?\d?\d)\.){3}(?:25[0-5]|2[0-4]\d|1?\d?\d)\bRejects octets above 255.
Hex color#(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})\bMatches #fff, #ffff, #ffffff and #ffffff80.
ISO date\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])Validates the shape, not calendar validity.
Slug^[a-z0-9]+(?:-[a-z0-9]+)*$Lowercase words separated by single hyphens.
Trailing whitespace[ \t]+$ with mClassic lint check.
Duplicate word\b(\w+)\s+\1\b with iBackreference \1 reuses the first group.

A few building blocks worth memorizing: \d digit, \w word character (ASCII letters, digits, underscore), \s whitespace, \b word boundary, (?:...) non-capturing group, (?=...) lookahead, (?<=...) lookbehind, and (?<name>...) for named groups you can read as match.groups.name.

Gotchas and performance

Catastrophic backtracking. Nested quantifiers such as (a+)+$ or (\w+\s?)*$ can take exponential time on input that almost matches. Against a 30-character non-matching string, the engine may try billions of paths and freeze the tab. If the tester becomes unresponsive on a longer text, that is the warning sign: rewrite the pattern so alternatives cannot match the same characters, use possessive-like constructs via lookahead, or anchor the pattern. The same pattern in server-side code is a denial-of-service vector (ReDoS).

\w and \d are ASCII-only in JavaScript even with the u flag. For non-Latin letters use \p{L} (letters) or \p{N} (numbers) with u enabled, for example [\p{L}\p{M}]+ to match words with combining marks.

Escaping inside strings. When you move a working pattern into new RegExp('...'), every backslash must be doubled. Regex literals (/.../) avoid this; prefer them for static patterns.

Lookbehind support. (?<=...) and (?<!...) have been supported in all modern browsers since 2023 (Safari 16.4). If you target older Safari, avoid them or use a capture group instead.

$ and \n. Without m, $ matches only at the very end of the string, and if the string ends with a newline, $ can also match just before it. Trim input when that matters.

  • Text diff for checking what a regex replacement changed between two versions of a file.
  • Word and character counter to measure the text you are matching against.
  • URL encoder when a matched URL needs to be encoded or decoded before use.
  • HTML entities for escaping matched snippets before inserting them into markup.
  • Case converter to normalize identifiers you extracted with a pattern.

FAQ

Which regex flavor does this tester use?

ECMAScript (JavaScript) regular expressions, run by your browser's own RegExp engine. Results match exactly what new RegExp(), String.prototype.match and replace() will do in your code. PCRE-only features such as recursion, possessive quantifiers and atomic groups are not supported.

Do I need to wrap the pattern in slashes?

No. Type the pattern body only, for example \d{3}-\d{4}, and toggle flags with the buttons. Slashes would be treated as literal characters.

Why does it find all matches even without the g flag?

The tester always iterates through the whole text so you can see every occurrence highlighted. The g toggle is still worth setting correctly because it changes how match(), matchAll() and replace() behave in your actual code.

Does it show capture groups?

Not yet. The tester highlights each full match and shows the total count. Groups are matched correctly, so a pattern that relies on them will still validate, but their contents are not listed separately.

Is my text uploaded anywhere?

No. Matching runs entirely in your browser; nothing is sent to a server, so you can safely test against logs or real data.

What happens with a pattern that matches an empty string?

Zero-width matches such as ^ or \b* are handled safely. The tester advances past empty matches to avoid an infinite loop and stops after 10,000 matches as a safety limit.