Quick reference
\d \w \s | digit, word character, whitespace (uppercase = the opposite) |
|---|---|
. | any character except newline (with the s flag, also newline) |
[abc] [^abc] [a-z] | one of, none of, a range |
* + ? {2,5} | repeat: 0+, 1+, 0 or 1, 2 to 5 times (add ? to make it lazy) |
^ $ \b | start, end (of line with m), word boundary |
(…) (?:…) (?<name>…) | capture group, non-capturing group, named group |
a|b | a or b |
(?=…) (?!…) | followed by, not followed by |
This tester uses the JavaScript regex engine, the same as Node.js and browsers.
Questions
Why does my regex work here but not in Python or Java?
Each language has small differences, for example named groups are (?P<name>…) in Python. Simple patterns work the same everywhere.
How do I use a capture group in the replacement?
Use $1, $2 for numbered groups and $<name> for named groups. $& inserts the whole match.
Why only one match?
Without the g (global) flag JavaScript stops at the first match. Tick g to find them all.
Is my text sent anywhere?
No. Matching runs in your browser.
More tools
- PDF editor — fill, sign, annotate and redact
- Compress image to a target size
- Image converter and resizer
- Images to PDF
- Merge PDF files
- Split PDF and extract pages
- Rotate PDF pages
- QR code generator — links, UPI, Wi-Fi, contacts
- URL shortener with click count
- Unit converter
- JSON formatter and validator
- JWT decoder
- Unix timestamp converter
- Base64 encoder and decoder
- Encrypt and decrypt text or files with a password
- Hash generator (MD5, SHA-256, HMAC)
- Strong password generator
- Cron expression explainer
- JSON to CSV converter (and CSV to JSON)