Regular Expression Patterns – Free, Online, Private
Twenty regular expressions with a reading of the tokens, the cases they miss, JavaScript, Python, and Go snippets, and a tester filled in with a sample.
- Email Regular Expression[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}
- URL Regular Expressionhttps?:\/\/[^\s<>'"]+
- IPv4 Address Regular Expression(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)
- IPv6 Address Regular Expression(?:[0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4}
- UUID Regular Expression[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}
- Hex Color Regular Expression#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})\b
- ISO Date Regular Expression\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])
- E.164 Phone Regular Expression\+[1-9]\d{7,14}
- Slug Regular Expression^[a-z0-9]+(?:-[a-z0-9]+)*$
- Semver Regular Expression^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$
- Strong Password Regular Expression^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^A-Za-z0-9]).{12,}$
- Integer Regular Expression^-?(?:0|[1-9]\d*)$
- Decimal Number Regular Expression^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?$
- Hexadecimal Regular Expression^(?:0x)?[0-9a-fA-F]+$
- Username Regular Expression^[a-zA-Z][a-zA-Z0-9_]{2,31}$
- Domain Name Regular Expression^(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$
- MAC Address Regular Expression^(?:[0-9a-fA-F]{2}[:-]){5}[0-9a-fA-F]{2}$
- 24-Hour Time Regular Expression^(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d)?$
- ISO 8601 Datetime Regular Expression^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$
- Base64 Regular Expression^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$
What these pages are
Each page is one expression you can run. The pattern is written out, the tokens are explained from the left, and a tester on the page is prefilled with a sample that contains both a match and a rejection. You can change the text or the pattern. The work stays in the browser. JavaScript and Python snippets are generated from the same source. The Go snippet uses RE2 and refuses lookaheads instead of emitting a program that will not compile.
These are practical patterns, not standards. The email expression is not RFC 5322. The IPv6 expression does not accept every legal compression. The semver expression is a subset of the published grammar. The page says what it skips. A pattern that claims to accept an entire specification in one line is usually wrong in a way the tests do not show. When the right tool is a parser, the page points at a parser.
Anchors are part of the pattern when the sample is a whole value, and they are omitted when the sample is a sentence. The m flag is set when the sample is several lines so that ^ and $ mean the line. Drop that flag when you copy the pattern onto a single field. The tester does not add a flag you cannot see.
The patterns
Email: A practical email pattern for finding addresses in text, not a full RFC 5322 parser. URL: Matches an http or https URL up to the next space or bracket. IPv4 Address: Matches a dotted IPv4 address whose octets are between 0 and 255. IPv6 Address: Matches a fully written IPv6 address of eight hextets. Compressed forms need a parser. UUID: Matches the 8-4-4-4-12 UUID text form and checks the version and variant nibbles. Hex Color: Matches a CSS hex color of 3, 4, 6, or 8 digits after a hash. ISO Date: Matches a YYYY-MM-DD date with a real month and a day from 01 to 31. E.164 Phone: Matches a leading plus, a non-zero country code, and 8 to 15 digits in total. Slug: Matches a lowercase slug of letters, digits, and single hyphens, one per line. Semver: Matches a practical MAJOR.MINOR.PATCH semver, with an optional prerelease and build. Strong Password: Requires 12 characters with a lower-case letter, an upper-case letter, a digit, and a symbol. Integer: Matches an optional minus and an integer with no leading zero. Decimal Number: Matches a JSON-style number: optional fraction, optional exponent, no leading zero. Hexadecimal: Matches a hex string with an optional 0x prefix. Username: Matches a 3 to 32 character username that starts with a letter. Domain Name: Matches a dotted domain with labels that do not start or end with a hyphen. MAC Address: Matches a six-octet MAC address with colons or dashes, not both mixed. 24-Hour Time: Matches a 24-hour time, HH:MM, with an optional :SS. ISO 8601 Datetime: Matches a datetime with a T, seconds, an optional fraction, and a Z or a numeric offset. Base64: Matches standard Base64, including the padding, and rejects a string that is the wrong length.
The full regex tester is the same engine without a preset. The visualizer draws a different view of a pattern. The converters do not evaluate regular expressions. They are linked from pages that need a next step, such as hex colors and Base64. If a pattern you need is not here, the last section of the client-side converters essay is the place that asks what is missing.
Frequently asked questions
Do these patterns run on a server?
No. The tester uses the browser's RegExp. The page is a static file.
Will the Go snippet always compile?
It will for these patterns, except the password policy, which uses lookaheads. That page explains the RE2 limit instead of calling MustCompile.
Should I anchor a pattern I copy?
Anchor it when the whole input must match. Leave it unanchored when you are finding a token inside a larger string. The page states which choice it made.
Are these safe against catastrophic backtracking?
They are written with alternations and counted quantifiers, not nested open-ended quantifiers. Still test a long input you care about. The tester stops drawing a huge number of matches.