Back to Home
Published: June 2026By Web Util Slyce Team8 min read

Regex Examples — Common Regular Expression Patterns

A collection of practical regex (regular expression) examples for common validation and matching tasks. Test any pattern interactively with our Regex Tester or generate patterns using AI Regex Generator.

Email Validation

/^[\w.-]+@[\w.-]+\.\w{2,}$/

✓ Matches

  • john@example.com
  • jane.doe@company.co.uk
  • user+tag@domain.org

✗ Does Not Match

  • not-an-email
  • @missing.com
  • user@.com

URL Matching

/https?:\/\/[\w.-]+(:\d+)?(\/[\w./-]*)?(\?[\w&=.-]*)?(#[\w-]*)?/

✓ Matches

  • https://example.com
  • http://site.com/page?id=1#section
  • https://api.example.com:8080/v1/users

✗ Does Not Match

  • ftp://file.com
  • just-a-string
  • www.example.com

Phone Number (US)

/\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}/

✓ Matches

  • (555) 123-4567
  • 555-123-4567
  • 555.123.4567
  • 5551234567

✗ Does Not Match

  • 12345
  • 555-1234
  • +1-555-123-4567

Strong Password Validation

/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!@#$%^&*]).{8,}$/

✓ Matches

  • P@ssw0rd!
  • Secure#1Pass
  • MyStr0ng!Pass

✗ Does Not Match

  • weak
  • onlylowercase1!
  • NOLOWERCAPS1!

IPv4 Address

/^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/

✓ Matches

  • 192.168.1.1
  • 10.0.0.255
  • 8.8.8.8

✗ Does Not Match

  • 256.1.2.3
  • 192.168.1
  • abc.def.ghi.jkl

Date (ISO 8601)

/^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{2}:\d{2})?)?$/

✓ Matches

  • 2026-06-01
  • 2026-06-01T14:30:00Z
  • 2026-06-01T10:00:00+05:00

✗ Does Not Match

  • 01/06/2026
  • June 1, 2026
  • 2026-13-01

Hexadecimal Color Code

/^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/

✓ Matches

  • #fff
  • #000000
  • #FF5733
  • #abc

✗ Does Not Match

  • #1234567
  • FF5733
  • #xyz
  • rgb(255,0,0)

Username Validation

/^[a-zA-Z][a-zA-Z0-9_]{2,15}$/

✓ Matches

  • john_doe
  • Alice123
  • dev_guy

✗ Does Not Match

  • ab
  • 1starts_with_digit
  • too_long_username_here
  • spaces not allowed

Extract All Hashtags

/#[a-zA-Z]\w*/g

✓ Matches

  • #javascript
  • #regex
  • #100DaysOfCode

✗ Does Not Match

  • #123
  • not a tag
  • ##double

Regex Quick Reference

PatternDescription
\dAny digit (0-9)
\wWord character (a-z, A-Z, 0-9, _)
\sWhitespace (space, tab, newline)
.Any single character (except newline)
*Zero or more of the preceding character
+One or more of the preceding character
?Zero or one (optional) of the preceding
{n,m}Between n and m occurrences
^Start of string anchor
$End of string anchor
(...)Capturing group
(?:...)Non-capturing group
|Alternation (OR)
[abc]Character class (a, b, or c)
[^abc]Negated character class (not a, b, or c)