Skip to content
BassoHub
Tools

Regex tester

Test JavaScript regex with live highlighting, named groups, flags and replace preview. Ready-made patterns for email, URL and IPv4. Free, in your browser.

Regular expression tester (JavaScript)

JavaScript syntax. Pasted a literal like /abc/gi? Pattern and flags are split automatically.

Flags
What does each flag do?
g
Global: Finds every occurrence, not just the first one.
i
Ignore case: Upper and lower case count as the same.
m
Multiline: ^ and $ match at the start and end of each line.
s
Dot all: The dot (.) also matches line breaks.
u
Unicode: An emoji counts as a single character and \p classes work (e.g. letters in any language).
v
Unicode sets: Unicode with set operations inside classes (ES2024). Can’t be combined with u.
y
Sticky: Only matches exactly at the current position, without skipping text.
d
Indices: Reports where each group starts and ends.
147 characters
  • $1 group 1
  • $<name> named group
  • $& whole match
  • $$ literal dollar sign

Everything runs in your browser: nothing you type is sent or stored.

Uses your browser’s JavaScript regex engine (the same as Node.js). PCRE, Python and Java have syntax differences: test in the environment where the regex will run.

How to use it

Type the pattern in the first field, without slashes: the tool shows the full literal, like /\d+/g, ready to copy into your code. Paste a whole literal (/abc/gi) and pattern and flags are split automatically. Tick the flags, paste your test text and the matches light up instantly, in two alternating colors so you can see where one ends and the next begins. Below, each match is listed with its position in the text and the value of every group.

Turn on Preview replacement to see the result of text.replace(regex, replacement) before it goes into your code. Not sure where to start? Open the ready-made patterns (email, URL, date, IPv4, hex color, slug and Brazilian formats like CEP, CPF, CNPJ and phone numbers): each one loads sample text with valid and invalid examples, one per line, and only the valid ones light up.

What is a regular expression?

A regular expression (regex) is a pattern that describes a set of strings. \d{4}-\d{2}-\d{2} means "four digits, a hyphen, two digits, a hyphen, two digits": an ISO date. With regex you find (every date in a document), validate (does this field look like an email?), extract (the year of each date) and replace (turn dd/mm/yyyy into yyyy-mm-dd). There are several dialects; this tool uses JavaScript's, the same one your browser and Node.js run.

JavaScript flags

  • g (global): finds every occurrence. Without it, only the first.
  • i (ignore case): /london/i matches "London" and "LONDON".
  • m (multiline): ^ and $ match at the start and end of each line, not just the whole text.
  • s (dotAll): the dot also matches line breaks.
  • u (unicode): emoji and other characters outside the basic plane count as one, and \p{...} classes work, such as \p{L} (any letter, in any language).
  • v (unicode sets): the successor of u (ES2024), with set operations inside classes, like [\p{L}--[a-z]]. It can't be combined with u.
  • y (sticky): only matches exactly at the current position, without skipping text. Handy for writing tokenizers.
  • d (indices): reports where each group starts and ends; the tool shows those positions next to each group.

Groups, named groups and replacement

Parentheses create capturing groups: in (\d{2})/(\d{2})/(\d{4}), the day is group 1, the month group 2 and the year group 3. Names make it readable: (?<day>\d{2})/(?<month>\d{2})/(?<year>\d{4}). In the replacement, $1 inserts group 1, $<year> the named group, $& the whole match and $$ a literal dollar sign. So the replacement $<year>-$<month>-$<day> turns "04/11/2026" into "2026-11-04". When you only want to group, without capturing, use (?:...).

Lookarounds: look without consuming

Lookarounds check what comes before or after without including it in the match. \d+(?= dollars) grabs the number in "150 dollars" but not the word. (?<!\$)\b\d+ grabs numbers not preceded by a dollar sign. There are four: (?=...) followed by, (?!...) not followed by, (?<=...) preceded by and (?<!...) not preceded by.

Why some regexes freeze (catastrophic backtracking)

JavaScript's regex engine tries paths and, when one fails, backs up and tries another. With nested quantifiers, like ^(a+)+$, the number of paths explodes: against "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa!" (30 letters and an exclamation mark at the end) the engine tries every way of splitting the 30 letters between the groups before giving up: over 500 million combinations. Each extra letter doubles the time. On servers this becomes the attack known as ReDoS; in 2019 a single firewall rule with this problem took down a large part of Cloudflare for almost half an hour.

How to avoid it:

  • Don't nest quantifiers over the same thing: (a+)+ is the same as a+.
  • Make alternatives mutually exclusive: (a|aa)* is risky (both alternatives match the same text), a* is not.
  • Prefer specific classes over .*: "[^"]*" instead of ".*".
  • Cap repetitions ({1,64}) and the input length before running the regex.

You can experiment safely here: the regex runs in a Web Worker, off the page. If it takes longer than 1 second, it is stopped and the tool tells you it is probably catastrophic backtracking.

Regex checks format, not validity

Format patterns (email, dates, Brazilian IDs) only check the shape. A real Brazilian CPF or CNPJ has check digits computed with modulo 11, and regex can't do arithmetic; 31/02/2026 has the right date format and doesn't exist; and the only real proof that an email address works is sending a confirmation message. Use regex to filter and format, and code to validate.

How the tool works

Everything runs in your browser, using its own regex engine (V8 in Chrome and Android, JavaScriptCore in Safari and on iPhone, SpiderMonkey in Firefox). Nothing you type is sent or stored. Matching runs in the background with a time limit and a cap of 1,000 matches; syntax errors show up immediately, with the engine's own message. Very new features, such as the v flag, depend on your browser version.

FAQ

Does it work the same in Python, PHP or Java? Mostly. The basics are the same, but there are differences: Python uses (?P<name>...) for named groups, PHP (PCRE) and Java have possessive quantifiers and the x flag, and JavaScript has no \A or \Z. Test in the environment where the regex will run.

Do I need to escape the slash? Only inside a literal (/a\/b/). With new RegExp("a/b") you don't. The Copy regex button already gives you the literal with escaped slashes.

What's the difference between .* and .*?? The first is greedy: it takes as much as possible and then gives back. The second is lazy: it takes as little as possible. In <b>one</b> and <b>two</b>, <b>.*</b> matches the whole sentence, while <b>.*?</b> matches each bold tag.

Why doesn't \w match "é" or "ñ"? In JavaScript, \w is only [A-Za-z0-9_]. For accented letters, use \p{L} with the u flag.

Why does regex.test() alternate between true and false? With the g (or y) flag, the regex stores the position of the last search in lastIndex and resumes from there on the next call. To just validate, drop the g.