Regex Tester for JavaScript
Test JavaScript regular expressions with live matches, groups and replace. كل شيء يعمل محليًا — لا يُرفع أي شيء.
- الإدخال
- Pattern · flags · test text
- الإخراج
- Matches · groups · replaced text
Test text
Scheduling rather than matching? Open the Cron Expression Generator
Test regular expressions as you type
This regex tester runs your pattern with the JavaScript engine in your own browser, the same one your Node.js or front-end code will use, and highlights every match in the test text as you type. Beside it you get the list of matches with their positions and capture groups, a replace preview, and a line-by-line explanation of what each part of the pattern does. Your pattern and text never leave the page.
How to test a regex
- Type the pattern between the slashes, without the surrounding
/…/, or load one from the Common patterns menu. - Switch flags on or off:
gto find every match,ito ignore case,mto make^and$work per line, and so on. - Paste or type your test text. Matches are highlighted in alternating colours so adjacent ones stay distinguishable.
- Open Matches for each match's position and groups, Explain for a plain-language breakdown, or Replace to preview a substitution using
$1,$<name>or$&.
Flags in JavaScript regular expressions
- g (global)
- Find every match rather than stopping at the first. Replace also replaces all of them.
- i (ignore case)
- Letters match regardless of case, so /cat/i finds Cat and CAT.
- m (multiline)
- ^ and $ match at the start and end of every line, not only of the whole text.
- s (dotAll)
- The dot also matches line breaks, which it otherwise skips.
- u (unicode)
- Treats the pattern as Unicode code points: emoji count as one character and \p{…} property escapes work. Stricter syntax.
- v (unicodeSets)
- The newer, stricter successor of u, adding set operations such as [\p{L}--[a-z]] inside classes. Shown only when your browser supports it.
- y (sticky)
- Each match must start exactly where the previous one ended; useful for tokenizers.
Groups, backreferences and replacement
Parentheses capture: (\d{4})-(\d{2}) stores the year in group 1 and the month in group 2. Give a group a name with (?<year>\d{4}) and it is also available as groups.year in code and as $<year> in a replacement. Use (?:…) when you need grouping for alternation or a quantifier but do not want to capture.
Inside the pattern, \1 or \k<name> matches the same text a group captured earlier, which is how the duplicate-words pattern in the library finds “the the”. Lookarounds such as (?=…), (?!…), (?<=…) and (?<!…) test what comes before or after without consuming it; the strong-password pattern uses four lookaheads to require each kind of character.
In the replacement string, $& inserts the whole match, $1–$99 a numbered group, $<name> a named group, $` and $' the text before and after the match, and $$ a literal dollar sign.
Quantifiers: greedy and lazy
Quantifiers say how many times the item before them may repeat: * zero or more, + one or more, ? zero or one, and {2,5} between two and five. By default they are greedy and take as much text as they can, then give some back if the rest of the pattern fails. Add a question mark to make one lazy: <.+?> matches a single HTML tag, while <.+> runs from the first < to the last > on the line.
The Explain tab spells this out for every quantifier in your pattern, so you can see at a glance which parts repeat, how often, and whether they are greedy or lazy. Character classes such as [A-Za-z0-9_] are listed range by range, and escapes such as \d, \w and \s are named, which makes a pattern you inherited from someone else much quicker to read.
Catastrophic backtracking, and why this tester will not freeze
Some patterns take exponential time on input they nearly match. The classic example is (a+)+$ against a long run of a’s followed by a b: the engine tries every way of splitting the a’s between the inner and outer repetition before giving up. In production this is a real denial-of-service risk, known as ReDoS.
Here the matching runs in a separate background worker with a time limit. If a pattern takes too long, the worker is stopped and you see a warning instead of a frozen tab. The usual fix is to remove nested quantifiers over the same characters, make alternatives mutually exclusive, or anchor the pattern. Results are capped at 10,000 matches.
A regex101 alternative focused on JavaScript
Tools such as regex101 support several regex flavours; this one deliberately supports exactly one, the ECMAScript engine in your browser, so what matches here matches in JavaScript and TypeScript. PCRE features such as possessive quantifiers, atomic groups and recursion are not available in JavaScript, and the explainer will treat their syntax literally. The library covers patterns people search for every day: email, URL, IPv4 and IPv6 addresses, ISO dates, hex colours, UUIDs, E.164 phone numbers, slugs, 24-hour times and strong passwords. Each is a pragmatic pattern, not a full RFC grammar; validate critical input with a dedicated parser too.
Working with schedules rather than strings? The Cron Expression Generator explains cron syntax the same way this tool explains regex.
الأسئلة الشائعة
- Which regex flavour does this tester use?
- JavaScript (ECMAScript), executed by your own browser's engine. Results match what RegExp, String.prototype.match and replace do in Node.js, Deno, Bun and browsers of the same version.
- How do I match across multiple lines?
- Turn on the m flag so ^ and $ match at each line, and the s flag if the dot should also match line breaks. Without s, use [\s\S] to match any character including a newline.
- How do I use a named capture group in a replacement?
- Name the group with (?<name>…) and refer to it as $<name> in the replacement string. Numbered groups are $1, $2 and so on, and $& inserts the whole match.
- Why does my regex only find the first match?
- Without the g flag, a JavaScript regex stops after the first match, and replace changes only that one. Switch on g to find and replace every occurrence.
- What is catastrophic backtracking?
- It is when a pattern with nested or overlapping quantifiers, such as (a+)+, makes the engine try an exponential number of paths on input that almost matches. This tester stops such runs after a time limit instead of freezing the page.
- What is a good regex for email addresses?
- A practical pattern is [A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}, which is in the library. No regex fully implements the email standard, so the only real test of an address is sending a confirmation email to it.
- Is my test data sent anywhere?
- No. Matching, replacing and the explanation all run in your browser, so you can safely test patterns against logs or customer data.