W

Regex pattern library

Curated patterns grouped by use case. Test any pattern in the regex tester.

Validation

  • Email address

    Common email validation pattern

    /^[\w.+-]+@[\w.-]+\.[a-zA-Z]{2,}$/
    • Anchored to start of string (^).
    • Anchored to end of string ($).
    • Matches word characters (\w).
    • Uses one-or-more quantifier (+).
    Test this pattern
  • ISO date (YYYY-MM-DD)

    Calendar date

    /^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/
    • Anchored to start of string (^).
    • Anchored to end of string ($).
    • Matches digits (\d).
    • Contains capturing or non-capturing groups.
    Test this pattern

Web & URLs

  • URL

    HTTP/HTTPS URLs

    /^https?:\/\/[\w.-]+(?:\.[\w.-]+)+[\w\-._~:/?#[\]@!$&'()*+,;=.]*$/i
    • Anchored to start of string (^).
    • Anchored to end of string ($).
    • Matches word characters (\w).
    • Uses one-or-more quantifier (+).
    • Uses zero-or-more quantifier (*).
    • Uses optional quantifier (?).
    • Contains capturing or non-capturing groups.
    Test this pattern
  • URL slug

    Kebab-case slug

    /^[a-z][a-z0-9]*(-[a-z0-9]+)*$/
    • Anchored to start of string (^).
    • Anchored to end of string ($).
    • Uses one-or-more quantifier (+).
    • Uses zero-or-more quantifier (*).
    • Contains capturing or non-capturing groups.
    Test this pattern

Data formats

  • IPv4 address

    Dotted decimal IPv4

    /^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/
    • Anchored to start of string (^).
    • Anchored to end of string ($).
    • Matches digits (\d).
    • Uses optional quantifier (?).
    • Contains capturing or non-capturing groups.
    Test this pattern
  • UUID v4

    Universally unique identifier

    /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i
    • Anchored to start of string (^).
    • Anchored to end of string ($).
    Test this pattern
  • Hex color

    #RGB or #RRGGBB

    /^#(?:[0-9a-fA-F]{3}){1,2}$/
    • Anchored to start of string (^).
    • Anchored to end of string ($).
    • Uses optional quantifier (?).
    • Contains capturing or non-capturing groups.
    Test this pattern

Text processing

  • Digits only

    One or more digits

    /^\d+$/
    • Anchored to start of string (^).
    • Anchored to end of string ($).
    • Matches digits (\d).
    • Uses one-or-more quantifier (+).
    Test this pattern