Skip to main content
CalcChef

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.

Mode
Flags

Flags in use: gm

Syntax cheat sheet (JavaScript)
JavaScript regular expression syntax
SyntaxMeaning
\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 \Bstart 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|balternation: 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

PresetPatternSample textMatches
Email[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
URLhttps?:\/\/[^\s]+Visit https://calcchef.com or http://example.org/pathhttps://calcchef.com | http://example.org/path
Date (ISO)\d{4}-\d{2}-\d{2}Dates: 2024-01-15, 2023-12-31, 2025-06-302024-01-15 | 2023-12-31 | 2025-06-30
IPv4\b(?:\d{1,3}\.){3}\d{1,3}\bServer IPs: 192.168.1.1, 10.0.0.255, 8.8.8.8192.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-446655440000550e8400-e29b-41d4-a716-446655440000
Hex color#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})\bColors: #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.21.2.3 | 2.0.0-rc.1+build.5
Credit card shape\b(?:\d{4}[ -]?){3}\d{4}\bTest 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-longalice_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

PresetTest textResultNote shown on the page
Email[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.
PhoneID 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), andhttps://example.com/a),It runs to the next space, so trailing punctuation such as ) or , is included in the match.
Date (ISO)2024-13-452024-13-45It checks the shape only: 2024-13-45 matches too.
IPv4999.999.999.999999.999.999.999It does not check that each number is 0 to 255: 999.999.999.999 matches.
UUID00000000-0000-0000-0000-00000000000000000000-0000-0000-0000-000000000000It 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.
Semverv1.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 shape1234 5678 9012 34561234 5678 9012 3456The 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.
Usernameab-_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

FlagWhat it does
gglobal: find every match
iignore case
mmultiline: ^ and $ match at each line
sdotAll: . also matches a line break
uunicode: full Unicode matching
vunicodeSets: set notation (replaces u)
dindices: match positions
ysticky: 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

  1. 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.
  2. Paste your own text into Test String. The matches are listed with their groups as you type.
  3. Tick or untick flags, and read the note under the preset for what it lets through.
  4. Switch to Replace and type a replacement, such as $<year> or an empty string to delete every match.
  5. 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 tools