← Back to Natanalysis

Regex Lab

Live highlighting · Group details · Replace preview · Cheatsheet

简体 繁體 English

Regular expression

/ /

Test string

Replacement

In the replacement string use $1 / $2 for capture groups, $& for the whole match, $<name> for a named group.


  

Match details

Hover or click an entry to locate it in the text above

Pattern explanation

A token-by-token walkthrough of the current pattern

Syntax cheatsheet

Click an item to insert it at the cursor

Ready-made patterns

One click loads the pattern, flags and a matching sample text.

Features

How to use

FAQ

Is the engine the same as on other regex sites?
This page runs your pattern with the JavaScript regex engine built into your own browser (ECMAScript). Nothing is sent to a server. Behaviour can differ slightly between Chrome / Firefox / Safari (mostly how soon new syntax is supported), and server-side flavors (Python / Java / PCRE) are similar but not identical, so check the engine you will actually deploy to.
Why does my pattern keep showing no matches?
Usual suspects: no g flag, so only the first hit counts; ^ and $ need m to work per line in multiline text; . does not match line breaks unless you turn on s; and backslashes sometimes get swallowed before reaching this page. The token explainer below shows how the engine actually reads your pattern.
How do $1 and $<name> work in the replacement?
The replacement string follows JavaScript String.replace rules: $& is the whole match, $1 / $2 are the first / second capture groups, $<name> is the named group, and $$ is a literal $. So a literal $ that is not followed by a reference must be written as $$.
What is the difference between greedy and lazy matching?
Quantifiers are greedy by default: .* eats as many characters as possible before the rest of the pattern matches. Adding ? makes them lazy (.*?), matching as few as possible. From "<a> <b>", <.*> matches the whole string, while <.*?> matches only <a> - try both here and watch the highlight.
Will my sensitive text be uploaded?
No. Matching, highlighting and replacing all happen in your browser's memory - this is a purely static page with no backend. Your text and pattern are only saved in your own device's localStorage so you can resume them next visit; the server never sees them.
Why does my pattern freeze the page?
That is catastrophic backtracking: with shapes like (a+)+ or ^(\w+\s?)*$ - a quantifier applied to a group that already contains a quantifier - the number of branches the engine must try explodes exponentially as soon as one character fails to match. 55 characters can take a minute and a half. This page runs matching on a separate thread with a hard 1 second timeout, so a timeout aborts that run and tells you why instead of freezing the tab. There is usually a nesting-free equivalent, e.g. ^\w+(?:\s\w+)*$ instead of ^(\w+\s?)*$.
How do I match line breaks? Why does . skip them?
The dot matches any character except a line break. Two options: ① turn on the s (dotAll) flag so . also matches line breaks; ② leave s off and write [\s\S] (or the equivalent [^]), which explicitly means "any character, line breaks included". If instead you want ^ and $ to work per line, turn on m.
Why does \d miss full-width digits? How do I match Chinese text?
\d is the same as [0-9] and only accepts half-width ASCII digits; full-width digits belong to the Unicode Nd category. For digits in any script turn on u and use \p{Nd}; for Chinese use [\u4e00-\u9fa5] or, with u, \p{Script=Han}. The cheatsheet's "Unicode & advanced" section here has one-click entries for both.
What happens if the replacement references a group that does not exist?
This one is easy to misread: $<name> becomes an empty string when the pattern has named groups but none called name, yet is kept literally when the pattern has no named groups at all; out-of-range numbers like $99 are kept literally too. The same string therefore behaves differently across patterns, so this page shows an inline note under the replacement box.
Why do (?i) or (?>a+) fail with a syntax error?
JavaScript supports neither inline flags like (?i) nor Python/PCRE-only syntax such as (?>…), \A, \Z, [[:alpha:]] or \R - they are syntax errors here. When such syntax is detected this page adds a note that it is backend-flavour regex; test those patterns in the engine you actually target, since this page only toggles the six flag buttons in the UI.

About

Regex Lab puts a pattern box, live-highlighted test text, match/group details, a replacement preview, a token explainer and a syntax cheatsheet on one page - covering the core workflow of RegExr and regex101.

Matching is executed by the browser's native RegExp engine; the explainer and cheatsheet are static data shipped with the page. There is no backend or third-party API, your input never leaves the browser, and the UI comes in English / 简体 / 繁體。

More tools

Runs entirely in your browser · Native RegExp engine · Free · 中文 / 繁體 / English

Usage Statement: None of the products or services sold on this website may be used for clinical diagnosis or treatment in humans or animals; they are intended for industrial or research purposes only.

Report Illegal or Harmful Information: service@natanalysis.com

© 2026 Shenzhen Natural Analysis Technology Co., Ltd. All rights reserved.

粤ICP备2025458111号-1·粤公网安备44030002007958号