Real-world regular expressions for validation, extraction, and text processing. Each pattern links to the live tester so you can experiment immediately.
Validates a basic email format — local part, @, domain, and TLD of at least 2 characters. Does not check whether the domain exists.
Use for: form validation, newsletter signups, contact forms.
Test this pattern →Matches: [email protected], [email protected] Rejects: @example.com, [email protected], user@com
Matches http and https URLs, with optional paths. Protocol is required to avoid false matches on plain words containing dots.
Use for: extracting links from text, link validation.
Test this pattern →Matches: https://example.com, http://site.com/path/page.html Rejects: example.com, ftp://files.example.com
Accepts international phone numbers with optional + prefix, spaces, hyphens, and parentheses. Length range covers most global formats.
Use for: international phone input fields, contact forms.
Test this pattern →Matches: +1 555-123-4567, (44) 20 7946 0958, 1234567890 Rejects: 123 (too short), +abc-def-ghij
Validates ISO-8601 date format with month (01–12) and day (01–31) range checking. Note: does not catch Feb 30 or leap-year edge cases — use a proper date parser for that.
Use for: date input validation, parsing ISO date strings.
Test this pattern →Matches: 2026-08-25, 1999-12-31, 2024-02-29 Rejects: 2026-13-01, 2026-08-32, 2026-8-25
Validates 24-hour time format. Hours 00–23, minutes 00–59.
Use for: time input in forms, meeting scheduler validation.
Test this pattern →Matches: 08:30, 23:59, 00:00, 14:05 Rejects: 24:00, 12:60, 8:30, 12:5
Matches valid IPv4 addresses where each octet is 0–255. Uses non-capturing groups (?:...) for cleaner matching.
Use for: network config validation, log parsing, IP extraction.
Test this pattern →Matches: 192.168.1.1, 10.0.0.255, 8.8.8.8 Rejects: 256.1.2.3, 192.168.1.300, .1.2.3
Matches full (non-abbreviated) IPv6 addresses — 8 groups of 1–4 hex characters separated by colons. Does not cover :: shorthand.
Use for: basic IPv6 validation, network tools.
Test this pattern →Matches: 2001:0db8:85a3:0000:0000:8a2e:0370:7334 Rejects: 2001:db8::1 (shorthand), 2001:xyz::1
Requires at least 8 characters with at least one lowercase, one uppercase, one digit, and one special character (\W = non-word character). Uses lookaheads ((?=...)) for each requirement.
Use for: password strength meters, registration validation.
Test this pattern →Matches: Passw0rd!, MyC4t$leeps, HelloWorld#1 Rejects: password, PASSWORD1, Pass1 (too short)
Alphanumeric characters and underscores only, 3–16 characters long. Common for forum signups, social handles, and developer usernames.
Use for: user registration, profile handles.
Test this pattern →Matches: john_doe, DevGuy42, a_b_c Rejects: abc (too short), user@name, a-very-long-username-here
Matches 3-digit and 6-digit hex color codes with # prefix. Case-insensitive for hex digits.
Use for: CSS color validation, color picker input.
Test this pattern →Matches: #fff, #4361ee, #F0F, #aabbcc Rejects: #abcd (4 chars), fff (no #), #gggggg
Matches 16-digit card numbers with optional spaces or hyphens every 4 digits. Use a Luhn check function for real validation — regex alone cannot detect valid card numbers.
Use for: payment form masking, basic format check.
Test this pattern →Matches: 4111111111111111, 4242 4242 4242 4242, 4111-1111-1111-1111 Rejects: 123456789 (wrong length), abcd-efgh-ijkl-mnop
Matches 5-digit ZIP codes with optional +4 extension.
Use for: address forms, shipping validation.
Test this pattern →Matches: 94105, 90210-1234, 10001 Rejects: 1234 (too short), 123456, 94105-123
Lowercase alphanumeric slug with single hyphens between words. No leading/trailing hyphens, no double hyphens.
Use for: URL generation, blog post slugs, product page URLs.
Test this pattern →Matches: hello-world, regex-tester, example, my-post-2026 Rejects: Hello-World, -leading, trailing-, double--hyphen
Matches an HTML open/close tag pair, capturing the tag name in group 1 and content in group 2. Uses the backreference \1 to match the closing tag name.
Use for: extracting HTML elements from markup, basic HTML parsing.
Test this pattern →Matching on "<div class="main">Content</div>": Group 1: div Group 2: Content
Matches integers and decimal numbers, with optional negative sign. Requires at least one digit before and after the decimal point.
Use for: numeric input validation, price/amount parsing.
Test this pattern →Matches: 42, -17, 3.14, -0.5, 100 Rejects: 3. (trailing dot), .5 (leading dot), 1,5 (wrong separator)
Validates domain names: labels separated by dots, each label 1–63 characters, TLD at least 2 letters. Lowercase only.
Use for: domain validation, link parsing, email domain extraction.
Test this pattern →Matches: example.com, sub.domain.co.uk, google.com Rejects: example, .com, -example.com, example-.com
Matches common file extensions at the end of a filename. Case-sensitive by default.
Use for: file type filtering, download link extraction.
Test this pattern →Matches: report.pdf, cover-letter.docx, data.zip, archive.tar.gz Rejects: file.pdfx, script.PDF (case mismatch), document
Matches MAC addresses in colon-separated or hyphen-separated format. Each of the 6 groups is 2 hex digits.
Use for: network device identification, hardware validation.
Test this pattern →Matches: 00:1A:2B:3C:4D:5E, 00-1A-2B-3C-4D-5E Rejects: 00:1A:2B:3C:4D:5G, 001A2B3C4D5E (no separator), 00:1A:2B:3C:4D (5 groups)
Matches the standard US Social Security Number format XXX-XX-XXXX. Does not validate SSN ranges or check against known invalid numbers.
Use for: form validation where SSN collection is required (HR, financial services).
Test this pattern →Matches: 123-45-6789, 987-65-4321 Rejects: 123456789 (no hyphens), 12-345-6789 (wrong format), 123-45-678 (wrong length)
Matches whitespace at the start or end of a string. In a replace operation, removing all matches trims the string. Use with the g (global) flag.
Use for: cleaning user input, normalizing strings, parsing CSV fields.
Test this pattern →In " hello world " matches: " " at start, " " at end After replacement: "hello world"
Save patterns, share with your team, use our AI regex explainer, and get syntax highlighting in every language. Just $2/month.
See Pro features →Each pattern above links to the live Regex Tester with the pattern pre-loaded. You can:
Important: Regex validation is a first-pass filter, not a security boundary. Server-side validation is mandatory for any data that enters your system. These patterns are starting points — adapt them to your specific requirements.
Some problems look like a job for regex but are better solved with a dedicated parser:
JSON.parse(). Regex breaks on nested structures.Date.parse() or a library.