RegEx Playground
Try 11 regex presets, from email, phone and IPv4 to semver and hex color, on sample text, see every match, and read what each pattern does not check. How it works
Use the RegEx Playground
JavaScript (ECMAScript) syntax. Features of other engines, such as (?i) or possessive quantifiers, are not supported. The pattern and text are saved in this browser until you clear them.
Flags in use: gm
Syntax cheat sheet (JavaScript)
| Syntax | Meaning |
|---|---|
| \d \w \s . | digit, word character (letter, digit, _), whitespace, any character except a line break |
| [abc] [^abc] [a-z] | one of a, b, c; none of them; a range |
| ^ $ \b \B | start of text (or line with m), end of text (or line with m), word boundary, not a word boundary |
| * + ? {n} {n,m} | zero or more, one or more, optional, exactly n, n to m times (greedy) |
| *? +? ?? {n,m}? | lazy versions: match as little as possible |
| ( ) (?: ) (?<name> ) | capturing group, non-capturing group, named group |
| \1 \k<name> | back-reference to group 1 or to a named group |
| a|b | alternation: a or b |
| (?=x) (?!x) | lookahead: followed by x, not followed by x |
| (?<=x) (?<!x) | lookbehind: preceded by x, not preceded by x |
Patterns from PCRE, Python or .NET may behave differently here. JavaScript has no possessive quantifiers (a*+), no atomic groups and no \A or \Z anchors (use ^ and $ without the m flag). An inline flag for the whole pattern such as (?i) is not supported; the scoped form (?i:…) works only in recent browsers.
About the RegEx Playground
A simple email regex is [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}, and in its sample text it finds [email protected] and [email protected]. The RegEx Playground loads eleven presets like it, from email, phone, URL and IPv4 to hex color, 24-hour time, semver, credit card shape and username, runs them as JavaScript regular expressions on your own text, and says what each one does not check. Explain this pattern breaks any pattern into its parts.
Presets and what they find in their sample text
| Preset | Pattern | Sample text | Matches |
|---|---|---|---|
| [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,} | Contact us at [email protected] or [email protected] | [email protected] | [email protected] | |
| Phone | (?<!\d)(?:\+\d{1,3}[\s.-]?)?(?:\(\d{3}\)|\d{3})[\s.-]?\d{3}[\s.-]?\d{4}(?!\d) | Call +1 415-555-0132 or (212) 555-0147, or 303.555.0189 after nine. | +1 415-555-0132 | (212) 555-0147 | 303.555.0189 |
| URL | https?:\/\/[^\s]+ | Visit https://calcchef.com or http://example.org/path | https://calcchef.com | http://example.org/path |
| Date (ISO) | \d{4}-\d{2}-\d{2} | Dates: 2024-01-15, 2023-12-31, 2025-06-30 | 2024-01-15 | 2023-12-31 | 2025-06-30 |
| IPv4 | \b(?:\d{1,3}\.){3}\d{1,3}\b | Server IPs: 192.168.1.1, 10.0.0.255, 8.8.8.8 | 192.168.1.1 | 10.0.0.255 | 8.8.8.8 |
| UUID | [0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12} | ID: 550e8400-e29b-41d4-a716-446655440000 | 550e8400-e29b-41d4-a716-446655440000 |
| Hex color | #(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})\b | Colors: #fff, #1A2b3C, #12345 and red. | #fff | #1A2b3C |
| Time (24-hour) | (?<![\d:])(?:[01]\d|2[0-3]):[0-5]\d(?!\d|:\d) | Meet at 09:30, lunch 12:15, last train 23:59. Not 24:00 or 7:5, and 12:30:45 has seconds. | 09:30 | 12:15 | 23:59 |
| Semver | ^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$ | 1.2.3 2.0.0-rc.1+build.5 1.02.3 1.2 | 1.2.3 | 2.0.0-rc.1+build.5 |
| Credit card shape | \b(?:\d{4}[ -]?){3}\d{4}\b | Test numbers: 4111 1111 1111 1111 and 5555-5555-5555-4444, not 1234 5678. | 4111 1111 1111 1111 | 5555-5555-5555-4444 |
| Username | ^[a-zA-Z][a-zA-Z0-9_-]{2,15}$ | alice_01 bob ab 9lives this-name-is-way-too-long | alice_01 | bob |
Every preset uses the flags g and m. Matches are separated by | here. The Semver and Username samples put one value on each line, because those patterns are anchored with ^ and $.
What each preset does not check
| Preset | Test text | Result | Note shown on the page |
|---|---|---|---|
| [email protected] [email protected] | [email protected] | [email protected] | A simple shape check: it accepts some addresses that are not valid and misses unusual valid ones. | |
| Phone | ID 12345678901234 | (no match) | North American style numbers (10 digits, optional country code). It checks the digit layout only, not area codes, and does not match other countries' formats. A number must not touch other digits, so ten digits inside a longer run of digits are not matched. |
| URL | (see https://example.com/a), and | https://example.com/a), | It runs to the next space, so trailing punctuation such as ) or , is included in the match. |
| Date (ISO) | 2024-13-45 | 2024-13-45 | It checks the shape only: 2024-13-45 matches too. |
| IPv4 | 999.999.999.999 | 999.999.999.999 | It does not check that each number is 0 to 255: 999.999.999.999 matches. |
| UUID | 00000000-0000-0000-0000-000000000000 | 00000000-0000-0000-0000-000000000000 | It checks the 8-4-4-4-12 hex layout only, not the version or variant digits. |
| Hex color | #ffff #ff8800cc | (no match) | The 3-digit and 6-digit forms only; 4-digit and 8-digit forms with an alpha channel are not matched. A value with 5 digits such as #12345 is not matched. |
| Time (24-hour) | 12:30:45 9:30 | (no match) | HH:MM from 00:00 to 23:59 with a two-digit hour. Seconds and 12-hour times with am or pm are not matched. |
| Semver | v1.2.3 | (no match) | Each version must stand alone on its line (the pattern is anchored with ^ and $). It follows the semver.org 2.0.0 rules, so leading zeros such as 1.02.3 and versions with a v prefix are not matched. |
| Credit card shape | 1234 5678 9012 3456 | 1234 5678 9012 3456 | The layout of 16 digits in groups of four only. It does not run the Luhn check, does not match 15-digit American Express numbers, and cannot tell a real card from a random number. Use test numbers: the text is saved in this browser. |
| Username | ab-_ | ab-_ | One common rule: 3 to 16 characters, starting with a letter, then letters, digits, _ or -. Sites differ, so change the lengths to match yours. Each name must stand alone on its line. |
Flags
| Flag | What it does |
|---|---|
| g | global: find every match |
| i | ignore case |
| m | multiline: ^ and $ match at each line |
| s | dotAll: . also matches a line break |
| u | unicode: full Unicode matching |
| v | unicodeSets: set notation (replaces u) |
| d | indices: match positions |
| y | sticky: each match must start where the last one ended |
The playground starts with g and m. Ticking u unticks v and the other way round, because JavaScript does not allow both.
How to use this tool
- Pick a preset, or keep Custom and type your own pattern. The preset fills in its pattern, the flags g and m, and sample text.
- Paste your own text into Test String. The matches are listed with their groups as you type.
- Tick or untick flags, and read the note under the preset for what it lets through.
- Switch to Replace and type a replacement, such as $<year> or an empty string to delete every match.
- Open Explain this pattern for a row per part: \d{4}-\d{2}-\d{2} reads as a digit, exactly 4 times, the text "-", and so on. The syntax cheat sheet lists the JavaScript tokens.
Frequently asked questions
- What is a regex for an email address?
- The Email preset, [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}. It checks the shape only: in the text [email protected] [email protected] it matches both [email protected] and [email protected], and it misses unusual valid addresses. Use it to find addresses in text; the only real test of an address is sending mail to it.
- What regex matches a US phone number?
- The Phone preset matches 10-digit North American numbers with an optional country code and a space, dot or dash between the groups. In its sample it finds +1 415-555-0132, (212) 555-0147 and 303.555.0189. A number must not touch other digits, so ID 12345678901234 gives no match, and it does not check area codes or other countries' formats.
- How do I match an IPv4 address with a regex?
- The IPv4 preset, \b(?:\d{1,3}\.){3}\d{1,3}\b, finds 192.168.1.1, 10.0.0.255 and 8.8.8.8 in its sample. It does not check that each number is 0 to 255, so 999.999.999.999 matches too.
- Which regex flags can I use?
- All eight JavaScript flags: d, g, i, m, s, u, v and y. The playground starts with g and m. u and v cannot be on together, so ticking one unticks the other. Without g only the first match is listed.
- Can I use a preset to validate a form field?
- Not as it stands. The presets find matches anywhere in the text, so the Email pattern also matches inside the sentence write to [email protected] today. For a check on a whole field, wrap the pattern in ^ and $ and drop the m flag: ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ then matches [email protected] but not that sentence. The pattern is JavaScript syntax, so a bare (?i) at the start is an error; use the i flag instead.
- Is my pattern saved?
- Yes, in this browser: the pattern, flags, test text, mode and replacement are kept in local storage until you press Clear Saved Values. A shared link fills in the pattern, flags and text it carries without overwriting what you saved.
Related Tools
View all toolsRegex Tester
Test a JavaScript regular expression on your own text: every match with its numbered and named groups and start and end positions, flag switches and replace.
GraphQL Query Builder
Test a GraphQL query in the browser: send it with variables and headers, pick fields from the introspected schema, read the response and copy it as cURL.
CIDR Calculator
Enter an IPv4 CIDR block such as 192.168.1.0/24 for its IP range, netmask, broadcast address and usable hosts, split it into subnets or turn a range into CIDR.
IP Address Viewer
See the public IP address your connection uses, with the approximate city, region, country and provider from ipapi.co, or look up any IPv4 or IPv6 address.
JS Minifier
Paste JavaScript to remove comments and unneeded whitespace. Line breaks the code relies on and /*! license comments stay; variable names are not shortened.
JS Object to JSON Converter
Paste a JavaScript object or array literal and get JSON. Unquoted keys, single quotes and trailing commas are accepted, and no code is run.