The flags
| Flag | Effect |
|---|---|
| g | Find every match, not just the first. |
| i | Ignore upper and lower case. |
| m | ^ and $ match at the start and end of each line. |
| s | . also matches line breaks. |
| u | Treat the pattern as Unicode. Needed for \p{...} classes and for characters outside the basic plane, such as emoji. |
Syntax you will use most
| Pattern | Matches |
|---|---|
| \d \w \s | A digit, a word character (letter, digit, underscore), whitespace |
| [abc] [^abc] [a-z] | One of the listed characters, none of them, a range |
| a* a+ a? a{2,4} | Zero or more, one or more, optional, between 2 and 4 |
| a+? a*? | The same, but as few as possible (lazy) |
| (abc) (?:abc) (?<name>abc) | Capture group, group without capture, named group |
| ^ $ \b | Start, end, word boundary |
| a(?=b) a(?!b) | a followed by b, a not followed by b (lookahead) |
In the replacement field, $1 inserts the first capture group, $& the whole match and $<name> a named group.
Which regex dialect is this?
The page uses your browser's JavaScript engine, so results match what you get in JavaScript and TypeScript code. Most patterns behave the same in Python, Java, Go and PCRE, with a few differences: JavaScript has no possessive quantifiers or atomic groups, and inline flags such as (?i) are not supported in every browser.
Questions
Why does my pattern match too much?
Quantifiers are greedy. ".*" runs from the first quote to the last one on the line. Use ".*?" or "[^"]*".
Why did the page freeze?
Some patterns take exponential time on certain input, for example nested quantifiers like (a+)+$. Reload the tab and simplify the pattern. The same pattern would stall your application too.
Do I need to escape a slash?
Not here. The pattern field holds only the part between the slashes of a JavaScript literal, so / can be typed as is.