Regular expression
Open to copy the pattern as JavaScript (literal / constructor), Python or Java.
Test string
Replacement
In the replacement string use $1 / $2 for capture groups, $& for the whole match, $<name> for a named group.
Match details
Pattern explanation
Syntax cheatsheet
Ready-made patterns
One click loads the pattern, flags and a matching sample text.
Features
- Live matching: every hit in the test text is highlighted as you type, alternating colors separate the matches.
- All six JavaScript flags - g / i / m / s / u / y - toggle with one click; invalid patterns report the engine's own error message.
- Match details list every hit with its offset and length, plus the value and range of every numbered and named capture group.
- A replacement view supporting $1, $& and $<name> references previews the rewritten text instantly, one click to copy.
- A token-by-token explainer and a syntax cheatsheet break any pattern down into plain language; common building blocks insert at the cursor.
- 100% client-side: your text is matched only by the RegExp engine inside your own browser - nothing is ever uploaded. UI in English / 简体 / 繁體.
How to use
- Type a pattern in the top field (no surrounding slashes needed) and toggle flags with the g/i/m/s/u/y buttons.
- Paste your text below - matches highlight instantly; if the pattern is invalid the reason appears under the input.
- Match details list every hit and its groups; hover an entry to locate it in the text. Fill in the replacement box to preview $-references.
- Learn unfamiliar syntax from the cheatsheet (click to insert) or load a ready-made pattern such as email, URL or IPv4 from the examples.
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
- MassCalc · Formula & MS Toolkit
- GlycoCalc · Glycan Mass Calculator
- PrimerCalc · Primer Tm Calculator
- SolutionCalc · Solution & Buffer Calculator
- ProteinCut · Peptide Digest Masses
- PepFragCalc · Peptide Fragment m/z
- GRAVYCalc · Protein Hydropathy
- SDS-PAGE-Calc · Gel Recipe Calculator
- Citation Generator
- Graphing Calculator
- Color Blindness Simulator & Palette Checker
- Text Diff & Review
- Venn Diagram Generator
- All online tools
Runs entirely in your browser · Native RegExp engine · Free · 中文 / 繁體 / English