JavaScript Regex Tester

Try a pattern on your text and review matching or replacement results. Optional AI assistance sends the description, pattern and flags to DeepSeek after confirmation.

Regular expression
Replace with

How to test a JavaScript regular expression

The tester runs a pattern against sample text using the same engine your browser uses, so what matches here matches in your application. Flags, every match with its position, capture groups and a replacement preview are shown together.

Patterns are JavaScript, or ECMAScript, rather than PCRE or Python syntax. The dialects overlap heavily but not completely, which is the most common reason a pattern that works elsewhere fails here. Ready-made patterns for e-mail addresses, URLs, IP addresses, UUIDs, dates, times, hex colours and numbers are one click away.

  1. Paste the text you want to search into the sample text field.
  2. Type the pattern without delimiters or flags, because the page adds them, or pick one of the quick patterns and edit it.
  3. Tick the flags you need: Global search, Ignore case, Multiline, Dot matches newline or Unicode.
  4. Read the match list: each entry shows the matched text, its index and any capture groups, which is how you find out why a group is empty.
  5. Enter replacement text to preview the substitution, then use Copy regex to take the final pattern into your code.

JavaScript regular expression details

Which flavour of regular expression this is

This is ECMAScript. Named groups written (?<name>...), lookbehind assertions (?<=...) and (?<!...), and Unicode property escapes such as \p{Letter} with the u flag are all available in current browsers. Possessive quantifiers, atomic groups, recursion, \A and \Z anchors, and inline mode modifiers such as (?i) are not part of the language.

Differences of this kind break patterns that were written for Python, PHP or Java. Translating (?P<name>...) to (?<name>...), replacing \Z with $, and moving flags out of the pattern into the flag checkboxes covers most of the real-world cases.

What each flag changes

Global search returns every match instead of stopping at the first, and it is also what makes a replacement apply throughout the text rather than only at the first hit. Ignore case makes letters match either case. Multiline lets ^ and $ match at line breaks inside the subject instead of only at the start and end of the whole string.

Dot matches newline lets a dot consume line terminators, which is what you want when matching a block of text. Unicode switches to code-point semantics, so a dot matches a full emoji rather than half of one, and enables the \p{...} property escapes.

Matches, groups and replacement tokens

Capture groups are numbered by the order of their opening parentheses, and a non-capturing group (?:...) keeps a group out of that numbering, which is useful when you only need the alternation. Named groups appear in the replacement as $<name>, which is far easier to read than $3 when a pattern grows.

In the replacement string, $1 to $99 insert captured groups, $& inserts the whole match, $$ inserts a literal dollar sign, and $` and $' insert everything before or after the match. Watch out for nested quantifiers such as (a+)+ against long input that almost matches: they can backtrack exponentially, which is the classic way a pattern freezes a page.

Practical details

Input & output

Accepts sample text, a JavaScript-compatible regex pattern, optional global/ignore-case/multiline/dot-all/unicode flags, and replacement text; displays every match and the resulting replacement output.

Common uses

Debugging a validation regex for form input; testing extraction of document numbers or dates from logs; previewing a regex replacement before committing it to code.

Processing & privacy

Regex matching and replacement run in browser JavaScript; AI Assist sends only the description, current regular expression, and flags to DeepSeek, never the tester text.

Limits & compatibility

The tester implements JavaScript regex semantics; date and address presets validate syntax only, not real calendar or postal values.

Frequently asked questions

Why does my pattern work in Python or PHP but not here?

The dialects differ. Python writes named groups as (?P<name>...) and has \Z; Java and PCRE support possessive quantifiers and atomic groups; PHP allows inline modifiers like (?i). ECMAScript has none of those, so the pattern has to be translated rather than copied.

Why is only the first match replaced?

The global flag is off. Without it, a replacement stops after the first match, which is the behaviour of String.prototype.replace when the pattern is not global.

Does the optional AI assistant see my test data?

No. Only the description you type, the current pattern and its flags are sent for a generation or explanation request, and only after you confirm. The sample text you are testing stays in the browser.

What is catastrophic backtracking?

A pattern with nested quantifiers can explore an exponential number of ways to fail, so a long non-matching string makes the engine appear to hang. Restructure the pattern to be more specific, prefer anchored alternatives, and test with a large realistic sample before shipping it.

How do I match text across several lines?

Use the Multiline flag when you want ^ and $ to match at line boundaries, and Dot matches newline when a single expression has to span the break. The two solve different problems and are often needed together.

Can I use the finished pattern in JavaScript directly?

Yes. Press Copy regex and use the pattern with the flags shown here, either as a literal such as /pattern/g or through new RegExp when the pattern has to be built from a variable. Remember to escape backslashes again if the pattern lives inside a string literal.

Recent tools: