Regex examples you can test: email, URL, IP
Patterns you can paste and try right now, what they truly validate, and the traps that make a regex accept too much or hang.
A regular expression describes a text pattern, and the fastest way to understand one is to run it against examples. In the regex tester you paste the pattern and a sample text, then see the matches highlighted, the groups and a breakdown of the pattern, all in your browser with nothing sent anywhere. These are the patterns the tool ships as presets, along with what each one accepts and what it doesn't check.
How to test a pattern, step by step
- Open the regex tester and type a pattern, or pick a preset.
- Switch on the flags you need:
gfinds every match instead of stopping at the first,iignores letter case andmmakes^and$apply to each line. - Paste the test text. Matches appear highlighted and in a list.
- Turn on Explain mode to read the pattern piece by piece.
The tool uses the JavaScript regular expression engine. If your pattern is for another language, features such as named groups or lookbehinds can behave differently.
Preset patterns
| Use | Pattern | What it checks |
|---|---|---|
^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$ | Something before the @, a domain and a dot | |
| URL | https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*) | An http or https address with a domain and optional path |
| IP v4 | ^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$ | Four groups of one to three digits |
| IP v6 | ^(?:[A-F0-9]{1,4}:){7}[A-F0-9]{1,4}$ | Eight groups of hex digits (full form only) |
Tested on samples, [email protected] matches the email pattern and ana@mail doesn't, since the domain has no dot. The tool also ships presets for Mexican phone numbers, RFC and CURP, useful if you work with Mexican data.
Reading a pattern piece by piece
Take the email preset, ^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$, and read it from left to right:
^and$: the whole text must satisfy what lies between them.[a-zA-Z0-9_.+-]+: one or more letters, digits, underscores, dots, plus signs or hyphens. This is the part before the @.@: a literal at sign.[a-zA-Z0-9-]+: one or more letters, digits or hyphens, the first part of the domain.\.: a literal dot, escaped so it doesn't mean "any character".[a-zA-Z0-9-.]+: the rest of the domain, which may contain more dots.
That breakdown is what Explain mode shows in the tester, and it's the best way to learn to write your own: change one piece and watch which matches appear or vanish.
A quick note on flags
Beyond g, i and m, the tester also records match positions, which is how it highlights each hit and each group in your text. If your test text has several lines and your pattern uses anchors, switch on m, otherwise ^ and $ only apply to the very start and end of the whole text.
What a pattern doesn't check
Format and validity are different things.
- IPv4:
999.999.999.999passes the preset, because it only demands one to three digits per group. A real validator would cap each group at 255. - IPv6: the preset matches only the full eight-group form, so shortened addresses using
::don't match. - Email: a sensible pattern accepts nearly everything common, but it doesn't prove the mailbox exists. Check the format loosely and confirm with a verification email.
- URL: the preset finds addresses in text, but it won't tell you whether the page loads.
Mistakes that keep recurring
- Forgetting anchors. Without
^and$, the pattern matches inside longer text. With them, the whole string must fit. - Not escaping the dot.
.means any character. For a literal dot, write\.. - Greedy matching.
.*swallows as much as it can. When you want the smallest match, try.*?. - Catastrophic backtracking. Some patterns, like nested quantifiers
(a+)+, can become extremely slow on certain inputs, a problem known as ReDoS. The tester evaluates in a Web Worker and, after 1.5 seconds, stops it and warns about a possibly inefficient pattern. - Using regex for everything. For whole HTML or JSON documents, a real parser is more reliable.
Named groups
A named group looks like (?<year>\d{4})-(?<month>\d{2}). Run on 2026-10, it returns year as 2026 and month as 10. It makes the pattern easier to read and lets code reach the parts by name. To tidy data before testing it, try the JSON formatter, and to compare two versions of a text, see see what changed between two versions of a text.
Frequently asked questions
What is a regular expression?
A pattern that describes a shape of text, used to search, validate or replace. For instance, a pattern can describe what an email or a ZIP code looks like.
What is a good regex for validating an email?
A reasonable one is ^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$. It accepts the usual forms but doesn't prove the mailbox exists.
Does an IPv4 regex check that the numbers are valid?
The preset doesn't: 999.999.999.999 passes. Each group would need to be limited to 255 for a real validation.
What do the g, i and m flags mean?
g finds all matches, i ignores letter case, and m makes ^ and $ work on each line.
What is ReDoS?
An expression that becomes extremely slow on certain inputs, usually because of nested quantifiers. It can freeze a program. The tester stops any evaluation that runs past 1.5 seconds.
Is my text sent to a server?
No. Evaluation happens in your browser.
Test your regex in the browser
Highlighted matches, groups, explain mode and protection against slow patterns. Runs locally, free, no signup.
Open Regex Tester →Related tools
- Regex Tester: matches, groups and explain mode.
- Text Diff: compare two versions of a text.
- Text Cleaner: sort, remove duplicates and number lines.
- HTML Entities: escape characters for HTML.
You might also like: best developer tools 2026, extract emails from a PDF, Word or CSV file, HTML entities and XSS: what to escape and where and URL encoding: what %20 means and when to encode.