Regex Tester
Guide: Regex Cheat Sheet for Beginners
Nothing you enter or choose here leaves your device. This tool runs in your browser.
A few patterns worth studying
The quickest way to learn regular expressions is to run small examples and see what lights up. Each of these is worth pasting in with a bit of matching text:
| Goal | Pattern | Note |
|---|---|---|
| Find ISO dates | \b(\d{4})-(\d{2})-(\d{2})\b | Three capture groups: year, month, day |
| Find hashtags | #\w+ | A hash followed by word characters |
| Rough email match | [^\s@]+@[^\s@]+\.[^\s@]+ | Finds addresses, doesn't prove they're valid |
| Password check | ^(?=.*\d)(?=.*[a-z]).{8,}$ | Lookaheads: has a digit, has a lowercase letter, 8 or more characters |
| Trim extra spaces | \s{2,} | Replace with a single space |
| Swap two words | (\w+) (\w+) | Replace with $2 $1 |
Greedy or lazy
Quantifiers like + and * grab as much as they can. On the text <b>bold</b>, the pattern <.+> matches the whole string, because the dot keeps going to the last closing bracket it can find. Add a question mark, as in <.+?>, and it becomes lazy and stops at the first one, giving two matches: <b> and </b>. If your match swallows more than you meant, this is almost always why.
What the flags do
gfinds every match instead of stopping at the first.iignores case.mmakes^and$match at each line, not only at the start and end of the text.slets the dot match line breaks as well.uturns on full Unicode handling, needed for emoji and many scripts.
Named groups across languages
Named groups make results easier to read, but the syntax differs. JavaScript, Java and PHP use (?<year>\d{4}). Python writes (?P<year>\d{4}). The tester has a mode for each language, so you can paste a pattern as it appears in your code. For Java, tick the option that treats the pattern as a string literal, so doubled backslashes are read as single ones.
When a pattern hangs
Some patterns take exponentially longer as the text grows. The classic is (a+)+$ run against aaaaaaaaaaaaaaaaaaaaaaaa!. The engine tries every way of splitting the a's before it gives up. The tester stops after two seconds and tells you. The cure is to remove the nested repeat or make each part more specific. In a real application, the same slow pattern on user input can be used to bring a server to its knees, so it's worth getting right.
A way of working
- Paste real sample text, including the awkward lines.
- Start with a simple pattern and add one piece at a time.
- Look at which parts are highlighted and which capture groups hold what.
- Test lines that should not match. A pattern that matches everything isn't useful.
- Use the replacement preview before you run a find-and-replace on real files.
The regex cheat sheet for beginners lists the building blocks. When you need to put a pattern in a string, the string escape tool handles the backslashes, and the text diff shows what a replacement changed. Matching runs in your browser, so sample data stays private.
Written by Akinrinmade Michael · Updated October 24, 2026
How to use
- 1Type your regular expression and choose the flags you need.
- 2Paste or type the text you want to test against.
- 3See every match highlighted, with its position and capture groups.
- 4Tick "Test a replacement" to preview the result of a find and replace.
Frequently asked questions
Which regex flavor does this use?
JavaScript mode uses your browser's own regular expressions. Java, PHP and Python modes accept each language's syntax and translate it so the browser can run it. Most patterns give the same results, and anything that can't be reproduced is reported. Go, .NET and others aren't added yet.
How do PHP and Python patterns work here?
In PHP mode, type the pattern with its delimiters and modifiers, like /\d+/i. In Python mode, use the flag boxes and (?P<name>...) for named groups. Both can read patterns pasted from code, and both give you a ready-made snippet to copy.
How do I test a pattern I copied from Java code?
Switch to Java, paste the text from between the quotes, and tick "Pattern is a Java string literal" so the doubled backslashes (\\d) become real ones (\d). Then use Copy as Java to get a Pattern.compile snippet back.
What do the flags mean?
g finds all matches instead of the first, i ignores case, m makes ^ and $ match at each line, s lets the dot match line breaks, and u turns on full Unicode support.
Why does it say my pattern took too long?
Some patterns, such as nested repeats like (a+)+, can take exponentially long on certain text. The tester stops after two seconds so your browser never freezes. Make the pattern more specific to fix it.
Is my text sent anywhere?
No. Matching runs in your browser, in a background worker, and nothing is uploaded.
Read the guide
Learn how this works and how to get the most from it.
Developer
Regex Cheat Sheet for Beginners
A plain-English guide to regular expressions: character classes, quantifiers, groups, flags and examples you can test.
3 min read
Related tools
Text Diff Checker
Compare two texts side by side and see exactly what changed.
String Escape / Unescape
Escape and unescape strings for JSON, JavaScript, Java, Python, HTML, SQL, regex and CSV.
JSON Formatter & Validator
Prettify, minify and validate JSON, with error line numbers.
SQL Formatter
Format and beautify SQL for MySQL, PostgreSQL, SQL Server and more.