JavaScript Regex Tester

Write a pattern, drop in some text, and watch the matches, groups, and replacements update as you type — no run button, no page reload.

Live preview

Copy Pattern

Test cases

Regex Tester

Live matching — updates as you type
—

Enter a JavaScript regular expression pattern without surrounding slashes. Suggestions may appear as you type.

Flags
— 0 matches — ms Pattern: 0 chars Input: 0 chars
0 characters 0 words 1 line
Matches: 0
Enter a pattern above to see matches highlighted here.
No capture groups yet. Add (…) to your pattern to inspect captured values, or click a match above to inspect it here.

How to Use the Regex Tester

Seven steps from a blank pattern field to a checked, working regex.

01
Type your pattern into the Pattern field — just the pattern itself, no surrounding slashes, so \d+ or ^hello rather than /\d+/.
02
Turn flags on or off as you need them. Global (g) starts checked, so you see every match instead of stopping at the first.
03
Paste your real test text (or a representative sample of it) into the Test Text box below.
04
Matches light up in the preview as you type, with a live count and a per-match breakdown underneath.
05
Click into Match Details, or click a highlighted match directly, to inspect numbered and named groups and each match’s exact position.
06
Need a substitution? Switch to the Replace tab and see the output update as you write the replacement string.
07
Copy the pattern, the matches, or the replaced text straight from the toolbar buttons — nothing to manually select first.

What’s in the Tool

Fifteen working parts, in the order you’ll actually reach for them.

Live matching

Matches update as you edit the pattern, flags, or test text. There’s no Run button to hunt for and no page reload — just an immediate answer to “does this actually match?”

Capture groups, every time

Each match lists its numbered groups separately from the full match, so you can see exactly what group 1, group 2, and so on captured — not just whether the overall pattern hit.

Replace preview

The Replace tab applies your replacement string — $1, $&, $<name>, all of it — to your test text and shows the result as you type, before it goes anywhere near your code.

Token-by-token explain

The Explain tab breaks a valid pattern into its pieces — anchors, groups, quantifiers, lookarounds — and describes each one in plain English, not just its official name.

Safety and performance panels

A static heuristic flags nested quantifiers and other backtracking risks before you run into them, next to real execution timing measured by your browser’s own engine.

History, favorites, and a command menu

Recent patterns save themselves, favorites hold onto the ones you reuse across projects, and Ctrl/Cmd+K puts every action a keystroke away.

Built-in cheatsheet

A reference table of character classes, anchors, quantifiers, and group syntax lives further down this page and inside the tool’s Reference tab, so you’re not tab-switching to look something up.

Built for small screens too

The editor, flags, and results panel hold up on a phone as well as a wide monitor, with touch targets sized for fingers and no sideways scrolling.

All seven JS flags

Toggle g, i, m, s, u, v, and y individually. Flags your browser hasn’t shipped yet, like v in older engines, are grayed out instead of failing silently.

Named groups by name

Patterns using (?<name>...) label each result by that name instead of just a position, which keeps a pattern with five or six groups actually readable.

Per-match detail

Beyond the highlighted preview, every match reports its matched text, start and end index, and length, so you’re not counting characters by hand.

Cross-engine compatibility check

Compares your pattern’s syntax against documented support in Python, PCRE2, Java, .NET, PHP, Ruby, RE2, and Rust. It’s a static reference, not eight live engines running in your browser, and it says so plainly.

Test case manager

Save a handful of named test cases with an expected match count, then run them all at once after you tweak a pattern to see what broke.

Working examples

Load a ready-made pattern for email-shaped strings, URLs, dates, hex colors, and more with one click, then bend it to your actual case.

Runs entirely in your browser

Your pattern and test text are matched using the JavaScript engine already loaded on the page. Nothing is sent to a server to compute a result.

Common Regex Examples

Nine patterns worth keeping on hand, each one a practical shortcut rather than a full spec for the format it covers. Click “Load Example” to drop one straight into the tool and start adjusting it.

Email (simplified)

^[^\s@]+@[^\s@]+\.[^\s@]+$

Checks that a string is roughly email-shaped: something, an @, something else, a dot. It’s a first filter, not a full email-address validator.

URL

https?:\/\/[^\s]+

Pulls links out of a paragraph of text, catching both http and https and stopping at the first whitespace.

Digits

\d+

The one you’ll reach for constantly — pulls out every run of whole numbers in a block of text.

Decimal Numbers

\d+(?:\.\d+)?

Handles whole numbers and decimals with one pattern, so a price list with both doesn’t need two passes.

Whitespace

\s+

Finds runs of spaces, tabs, or line breaks — pair it with the Replace tab to collapse them down to one space.

Date (YYYY-MM-DD)

^\d{4}-\d{2}-\d{2}$

Confirms a string is shaped like an ISO date. It won’t catch a February 30th — that check needs actual date logic, not regex.

Hex Color

^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$

Validates a 3- or 6-digit hex color, shorthand or full — useful for checking user input before it hits a stylesheet.

Username

^[A-Za-z0-9_]{3,16}$

A straightforward username rule: letters, digits, and underscores, between 3 and 16 characters long — adjust the bounds for your own signup form.

IPv4 Address

^(?:\d{1,3}\.){3}\d{1,3}$

Checks for four dot-separated number groups. It won’t reject 999.999.999.999 — bounding each octet to 0–255 needs a longer pattern than most cases call for.

Regex Flags

A flag changes how a pattern is applied without changing a single character of the pattern itself. JavaScript has seven of them, and every one here behaves exactly as your browser’s engine defines it — nothing custom layered on top.

FlagNameWhat it doesExample
gGlobalFinds every match instead of stopping after the first one/\d+/g
iIgnore CaseMatches letters regardless of case/hello/i matches “Hello”
mMultilineMakes ^ and $ match the start/end of each line, not just the whole string/^Line/m
sDotAllLets . match line-break characters, which it skips by default/a.b/s
uUnicodeTreats the pattern as Unicode code points, needed for astral characters and \u{...} escapes/\u{1F600}/u
vUnicode SetsAn extension of u with set operations inside character classes; newer browsers only/[\p{L}–[a-z]]/v
yStickyMatches only starting at the position of lastIndex, without scanning ahead/\d/y

What Is a Regular Expression?

A regular expression, regex or regexp for short, is a pattern that describes the shape of text rather than one exact string. Instead of searching for a literal word, you describe something like “a run of digits,” “anything shaped like an email address,” or “a line starting with a capital letter,” and the engine finds every stretch of your input that fits.

In practice, that shape-matching gets reached for constantly:

  • Pulling every number, date, or ID out of a larger block of text
  • Checking that a form field roughly matches an expected format, like a username or a hex color
  • Extracting structured values out of log lines, URLs, or CSV rows
  • Swapping every occurrence of something — a placeholder, a stray character — for something else
  • Parsing lightly structured text without reaching for a full parser

None of this looks identical from language to language. Python, PHP, .NET, and JavaScript each ship their own regex engine, and while they share a common ancestor, the details drift apart — lookbehind support, Unicode handling, and even flag names differ. This tool is built specifically around JavaScript’s engine, which the next section covers in more detail.

Regex vs. Plain Text Search

If you only ever need to find one exact string, a plain text search will always be simpler and faster than a regex — searching for "apple" doesn’t call for a pattern language. Regex starts earning its keep once the rule isn’t a fixed string: “apple” or “orange,” any four-digit number, anything sitting inside quotes. A pattern like /apple|orange/gi catches either word in either case in a single pass, where the plain-string equivalent means writing out several separate checks by hand.

FAQs

Frequently Asked Questions

A regex tester lets you check whether a pattern matches the text you expect, right as you type it, instead of running a script just to find out.
Yes to both — it’s free, runs entirely at minifycssjs.com/regex-tester/, and there’s nothing to sign up for or install.
It runs on your browser’s actual RegExp engine — the same one your code runs on — so there’s no separate implementation to second-guess.
g, i, m, s, u, v, and y. Your browser tells the tool which ones it actually supports, so newer flags like v gray out automatically in older browsers instead of silently doing nothing.
Yes. The Replace tab runs your replacement string — including $1, $<name>, and $& — against your test text and shows the result live.
Not necessarily — that’s what the Compatibility tab is for. It checks your pattern’s syntax against documented support in Python, PCRE2, Java, .NET, PHP, Ruby, RE2, and Rust, as a static reference, not a live test in those languages.
No. Matching happens entirely in your browser using the JavaScript engine already running the page — nothing is uploaded to a server.