What are regular expressions?
Regular expressions (regex) are a compact language for describing text patterns. They let you search, replace and validate complex structures in a single line. Nearly every programming language supports them — JavaScript, Python, PHP, Java — as do editors and command-line tools. Typical uses: validating emails and phone numbers, extracting data from text, and cleaning files.
How to use the tester
- Type your pattern without the surrounding slashes.
- Add flags:
gfor all matches,ito ignore case,mfor multiline,sso dot matches newlines,ufor Unicode. - Enter a test string and watch matches highlight instantly.
- Check the match table for each match's index and captured groups.
- Enter a replacement using
$1,$2for groups — like the example that reformats dates.
Working with Unicode
In JavaScript, \w only matches ASCII letters, digits and underscore. For letters in any language use \p{L} with the u flag, or a script range such as [\u0600-\u06FF] for Arabic. Likewise, \b only understands ASCII words; use lookarounds like (?<!\p{L}) for Unicode-aware boundaries.
Handy patterns
- US ZIP code:
^\d{5}(-\d{4})?$ - UK postcode (simplified):
^[A-Z]{1,2}\d[A-Z\d]? ?\d[A-Z]{2}$ - Strong password (8+, upper, lower, digit):
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{8,}$ - Hex color:
^#(?:[0-9a-fA-F]{3}){1,2}$
To apply a replacement across a long text, use Find & Replace, which supports regex too.
Quick regex cheat sheet
| Token | Meaning |
|---|---|
. | Any character except newline |
\d / \w / \s | Digit / letter, digit or _ / whitespace |
* / + / ? | Zero or more / one or more / optional |
{2,5} | Between 2 and 5 times |
^ / $ | Start / end of line |
[a-z] / [^0-9] | Character set / anything but digits |
( ) / | | Capture group / alternation |
Regex with non-Latin text
In JavaScript, \w matches only Latin letters. To match Arabic, use the range [\u0600-\u06FF] or the Unicode property \p{Script=Arabic} with the u flag. Diacritics are separate characters, so you may want to strip them first with Remove Tashkeel.
Frequently Asked Questions
Which regex engine is used?
Your browser's built-in JavaScript engine — largely compatible with other languages, with minor differences in advanced features.
Why doesn't \w match accented or Arabic letters?
In JavaScript \w is ASCII-only. Use \p{L} with the u flag.
What does the g flag do?
It finds every match instead of stopping at the first.
How do I reference a group in the replacement?
Use $1 for the first group, $2 for the second, or $
Is my text sent to a server?
No. Everything runs in your browser.
Last updated: