Skip to main content
Back to Tools

Regex Tester

Test JavaScript regular expressions in real time. Paste a pattern, see every match highlighted, and copy the result when you're done.

TL;DR. Type a pattern and flags on the left, paste the text you want to search on the right, and every match lights up with its index and any named groups. The engine is the same JavaScript RegExp you'd use in Node or the browser, so if it works here it works in your code. Click a preset below to load a tested pattern for emails, URLs, phone numbers, IPs, dates, or hex colors.

//
No matches found.

How to use the regex tester

  1. Pick a starting pattern. Click a preset (Email, URL, US Phone, IPv4, ISO Date, Hex Color) or type your own into the Regex Pattern input. The slashes on either side are part of the UI, not the pattern — don't type them yourself.
  2. Set your flags. g for every match, i for case-insensitive, m for multi-line anchors, s to let . match newlines, u for full Unicode (required when the input contains emoji). Combine them — for example gi.
  3. Paste real data into the test string. A pattern that matches a hand-written example can still fail in production because of smart quotes, trailing whitespace, or encoding differences. Paste the actual log line, CSV row, or user input you need to cover.
  4. Read the match list. Each card shows the matched text, its index, and any named groups you captured with (?<name>...). Up to 1000 matches are displayed — enough to validate any realistic pattern.
  5. Copy it into your code. When you paste the pattern into a new RegExp("...") constructor, double every backslash — \d in the tester becomes "\\d" in a string literal. Literal regex syntax (/pattern/flags) does not need the extra escape.

Regex cheatsheet

Every pattern is built from these building blocks. Keep this table open while you experiment.

TokenMeaning
.Any character except newline (add s flag to include newlines)
\d \DDigit / non-digit
\w \WWord character [A-Za-z0-9_] / non-word
\s \SWhitespace / non-whitespace
^ $Start / end of string (or line with m flag)
\b \BWord boundary / non-boundary
* + ?Zero-or-more / one-or-more / optional
{n} {n,m}Exactly n / between n and m repetitions
[abc] [^abc]Character class / negated class
(x) (?:x)Capturing / non-capturing group
(?<name>x)Named capturing group
(?=x) (?!x)Positive / negative lookahead
(?<=x) (?<!x)Positive / negative lookbehind
x|yAlternation (match x or y)

Common patterns, ready to paste

  • Email (loose, good for UX validation): [A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}. Do not use this for authoritative deliverability — the RFC grammar is far wider than anything regex can express cleanly.
  • URL: https?://[^\s)]+. Stops at whitespace or a closing parenthesis so it plays well with Markdown link syntax.
  • US phone number: \(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}. Covers (415) 555-0133, 415.555.0133, and 415-555-0133.
  • IPv4 address: \b(?:\d{1,3}\.){3}\d{1,3}\b. Fine for extracting candidates; do a numeric range check afterwards.
  • ISO date (YYYY-MM-DD): \d{4}-\d{2}-\d{2}.
  • Hex color: #(?:[0-9a-fA-F]{3}){1,2}\b. Matches both #f0a and #ff00aa.

Frequently asked questions

What is a regex tester and when should I use one?+
A regex tester lets you try a regular expression against real text and see exactly what it matches before pasting it into production code. Use it when you are validating user input (emails, phone numbers, postal codes), scraping patterns out of logs, building search-and-replace rules, or debugging why a pattern you copied from Stack Overflow is not matching what you expected.
Which regex flavor does this tool use?+
This tool uses the JavaScript (ECMAScript) RegExp engine that ships with your browser. It is the same engine used by Node.js, React, Next.js, and anything you write in .js or .ts. If you are writing Python, Ruby, Go or PCRE you should double-check flavor-specific features like named groups, lookbehind support, and the dot-all flag before relying on the match.
What do the g, i, m, s, u, y flags do?+
g returns every match instead of just the first. i makes the pattern case-insensitive. m switches ^ and $ to match line boundaries instead of the whole string. s makes the dot match newlines. u enables full Unicode matching (needed for emoji). y (sticky) anchors matches to the lastIndex position. You can combine them, for example "gi" for a case-insensitive global match.
Why does my pattern work here but fail in my backend code?+
Three common causes. First, flavor drift: JavaScript does not support every feature PCRE or Python does. Second, string escaping: a pattern typed as \d in the tester needs to be \\d inside a double-quoted string literal. Third, input differences: trailing whitespace, BOM characters, or smart quotes in your real data that are not in your sample text.
Can regex catastrophically backtrack and freeze the tool?+
Yes. Patterns like (a+)+$ run against long strings will exponentially backtrack. This tool caps global matches at 1000 and the browser will usually recover, but avoid nested quantifiers on unbounded input. If you need to parse deeply nested structures, use a real parser (JSON.parse, an HTML parser, etc.) instead of regex.
Do you send my regex or test string to a server?+
No. Everything runs in your browser with the built-in RegExp object. Nothing leaves your machine, no signup is required, and the tool works offline once the page is loaded.

Related developer tools

Sponsored

Ad served by Adsterra. OpenAIToolsHub is not responsible for advertiser content.