
Which regex flavor this tester runs
A pattern copied from Python or PHP does not always work in JavaScript. This tester runs on the JavaScript engine of your own browser, so a pattern acts here the same way it does in a web page or in Node.js. PHP uses a library called PCRE, and Python has its own re module. Most signs mean the same in all three. The table lists where they differ.
| What you want | JavaScript | Python | PCRE (PHP) |
|---|---|---|---|
| A named group | (?<name>...) | (?P<name>...) | (?<name>...) |
| A group in the replacement | $1 $<name> | \1 \g<name> | $1 \1 |
| Very start and end of the text | ^ and $ without the m flag | \A \z | \A \z |
Does $ match before a last line break? | No | Yes | Yes |
Does \w match é or ж? | No, also not with the u flag | Yes | Only in UCP mode |
| Flags inside the pattern | Only for a part, like (?i:abc), in browsers from 2025 on | (?i) at the start, or (?i:abc) | (?i) anywhere |
Atomic groups (?>...) and a++ | No | Yes, since Python 3.11 | Yes |
| Lookbehind length | Any length | Fixed length only | Limited |
We checked the Python column against the Python re documentation in November 2026.
Regex cheat sheet
Letters and digits match themselves. The signs . * + ? ^ $ ( ) [ ] { } | \ / have a meaning, so put a backslash before one to find the sign itself.
| Pattern | Matches | Example |
|---|---|---|
| . | Any character except a line break | c.t finds cat, cut, c7t |
| \d \w \s | A digit, a word character (A to Z, a to z, 0 to 9, _), white space | \d\d finds 42 |
| \D \W \S | Anything except a digit, a word character, white space | \S+ finds each word |
| [abc] [a-z] | One character from the set or the range | gr[ae]y finds gray and grey |
| [^abc] | One character not in the set | [^,]+ finds the text between commas |
| ^ $ | Start and end of the text, or of each line with the m flag | ^# finds a # at the start |
| \b | A word edge | \bcat\b skips category |
| * + ? | The part before it zero or more times, one or more times, or optional | colou?r finds color and colour |
| {3} {2,} {2,4} | Exactly 3 times, 2 or more times, 2 to 4 times | \d{4} finds 2026 |
| a|b | a or b | cat|dog |
| (...) | A group that saves its match as $1, $2 | (\d+) kg |
| (?:...) | A group that does not save | (?:ab)+ finds ababab |
| (?<name>...) | A named group | (?<year>\d{4}) |
| \1 \k<name> | The same text a group found before | (\w)\1 finds the ll in hello |
| (?=...) (?!...) | Followed by, not followed by | \d+(?=%) finds the 15 in 15% |
| (?<=...) (?<!...) | After, not after | (?<=\$)\d+ finds the 40 in $40 |
| \p{L} | A letter in any alphabet (needs the u flag) | \p{L}+ finds Москва |
| \. \( \\ | The sign itself: a period, a bracket, a backslash | 3\.5 finds 3.5 |
The MDN guide to regular expressions lists every part of the JavaScript syntax with more examples.
Greedy and lazy: .* or .*?
A repeat sign like + or * is greedy. It takes as much text as it can. On <b>bold</b>, the pattern <.+> runs from the first < to the very last >.
A ? right after the repeat sign makes it lazy, so <.+?> stops at the first >. A set that leaves out the end sign often works better: <[^>]+> also stops at the first > and never has to step back.
Flags
Flags change how the whole pattern works. In code they go after the last slash, like /cat/gi.
| Flag | Name | What it does |
|---|---|---|
| g | global | Finds every match, not only the first. Without it, replace changes only the first match. |
| i | ignore case | A and a count as the same letter. |
| m | multiline | ^ and $ match at the start and end of every line, not only of the whole text. |
| s | dot all | The dot matches line breaks too. |
| u | unicode | An emoji counts as one character, \p{...} works, and mistakes like \e become errors. |
| v | unicode sets | Everything u does, plus set math like [\p{L}--[a-z]]. Use u or v, not both. |
| y | sticky | Each match must start exactly where the last one ended. |
| d | indices | Gives the start and end of each group in the result. |
Turn on u when your text has emoji. Without it, JavaScript sees 😀 as two halves, so ^.$ does not match it.
Catastrophic backtracking

(a+)+ can try to match.A few patterns take time that doubles with every extra character. The classic case is ^(a+)+$ on a row of a's that ends in a b. The engine tries every way to share the a's between the inner + and the outer + before it gives up. For 30 letters that is about half a billion ways.
This tester stops a test after 2 seconds. On a server there is no such stop, and a slow pattern can be used to block it, an attack called ReDoS. To avoid it, never put a repeat inside a repeat when both can match the same text, as in (a+)+ or (\w+\s?)*. Prefer a set like [^,]* over .*.
Common patterns and where they fail
Each of these patterns has gaps. "Try it" loads one into the tester with a text that shows where it fails.
| For | Pattern | Where it fails | Load |
|---|---|---|---|
| Email address | /[\w.+-]+@[\w-]+(?:\.[\w-]+)+/g | Finds most everyday addresses. It misses addresses with letters like é and quoted names, and it skips me@localhost, which works on some local networks. It does not check that the address is real. | |
| Web link | /https?:\/\/[^\s<>"]+/g | Takes a period or a bracket at the end of a sentence as part of the link. Misses links without http, like www.example.com. | |
| Date as 2026-11-07 | /\b(?<year>\d{4})-(?<month>0[1-9]|1[0-2])-(?<day>0[1-9]|[12]\d|3[01])\b/g | Checks the month (01 to 12) and the day (01 to 31), but still takes 2026-02-31. Check real dates in your code. | |
| Number | /-?\d+(?:\.\d+)?/g | Reads 1,250.50 as two numbers and 1.2.3 as two. Decimal commas, like 3,5 in much of Europe, are not covered. | |
| Hex color | /#(?:[\da-f]{8}|[\da-f]{6}|[\da-f]{3,4})\b/gi | Also takes words like #fade or #bad that use only the letters a to f. | |
| Phone number (US) | /\(?\b\d{3}\)?[-. ]?\d{3}[-. ]?\d{4}\b/g | Only the ten digit North American form. Numbers from other countries have other lengths and groups. | |
| Doubled words | /\b(\w+)\s+\1\b/gi | Works only with the letters A to Z. With the i flag "The the" counts too, and the replacement keeps the first one. | |
| Spaces at line ends | /[ \t]+$/gm | Needs the m flag, or only the very end of the text is checked. Spaces at the start of lines stay. | |
| Double spaces | / {2,}/g | Only plain spaces. Tabs and no break spaces stay; [ \t\u00A0]{2,} catches those too. | |
| Empty lines | /^[ \t]*\r?\n/gm | An empty last line with no line break after it stays. | |
| HTML tags | /<[^>]+>/g | Breaks on a > inside an attribute or a comment. Never use it to make HTML safe; use a real HTML parser for that. | |
| IPv4 address | /\b(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\b/g | Rejects numbers over 255. In 1.2.3.4.5 it still finds 1.2.3.4, and it knows nothing of IPv6. | |
| Words in any alphabet | /\p{L}+(?:['’]\p{L}+)*/gu | Needs the u flag. Splits words at a hyphen, and Chinese or Japanese text with no spaces counts as one long word. |
No pattern can prove that an email address or a date is real. Use the pattern to find likely matches, then check each one in your code. To run a pattern over a whole document, with undo and several rules in a row, use find and replace.