Skip to main content

Common Regex Patterns

Browse common JavaScript regex patterns with copyable expressions, examples, and limits. Search stays local; these basic patterns do not validate complete real-world formats.

Showing 10 of 10 patterns

  • ASCII words

    Text

    Find runs of ASCII letters bounded by word boundaries.

    Pattern\b[A-Za-z]+\b

    Flags: g

    Matching example
    Regex patterns are useful.
    Limitation
    ASCII letters only; non-ASCII letters can act as boundaries and produce partial matches.
  • Digits only

    Text

    Require one or more decimal digits across the whole string.

    Pattern^\d+$

    Flags: none

    Matching example
    2048
    Limitation
    JavaScript \d matches ASCII digits; signs, spaces, and separators are not allowed.
  • Surrounding whitespace

    Text

    Find whitespace at the start or end of a string.

    Pattern^\s+|\s+$

    Flags: g

    Matching example
    hello
    Limitation
    Use with a global replace by an empty string; internal whitespace is unchanged.
  • Email address (basic shape)

    Contact

    Check for non-space text around an @ sign and a later dot.

    Pattern^[^\s@]+@[^\s@]+\.[^\s@]+$

    Flags: none

    Matching example
    alex@example.com
    Limitation
    Not full email-standard validation and cannot confirm that an address exists.
  • North American phone number (basic)

    Contact

    Match a 10-digit North American number with optional country code and common separators.

    Pattern^\+?1?[\s.-]?(?:\(\d{3}\)|\d{3})[\s.-]?\d{3}[\s.-]?\d{4}$

    Flags: none

    Matching example
    +1 (415) 555-0132
    Limitation
    Checks a common shape only; it does not validate numbering plans or assignment.
  • HTTP(S) URL (basic)

    Web

    Require an http:// or https:// prefix followed by non-whitespace characters.

    Pattern^https?:\/\/\S+$

    Flags: none

    Matching example
    https://example.com/a?b=1
    Limitation
    Does not parse, normalize, or confirm that a URL can be reached.
  • Date shape (YYYY-MM-DD)

    Date and region

    Match four digits, a hyphen, two digits, a hyphen, and two digits.

    Pattern^\d{4}-\d{2}-\d{2}$

    Flags: none

    Matching example
    2026-02-28
    Limitation
    Checks the text shape only; impossible calendar dates also match.
  • US ZIP code

    Date and region

    Match five digits with an optional four-digit extension.

    Pattern^\d{5}(?:-\d{4})?$

    Flags: none

    Matching example
    02139-1234
    Limitation
    US format only; does not confirm that a code is assigned.
  • Username (ASCII)

    Identifiers and formats

    Allow 3–16 ASCII letters, digits, or underscores.

    Pattern^[A-Za-z0-9_]{3,16}$

    Flags: none

    Matching example
    ada_42
    Limitation
    Only an example rule; adapt it to the actual product’s account policy.
  • Hex color (3 or 6 digits)

    Identifiers and formats

    Match a 3- or 6-digit hexadecimal color with an optional leading #.

    Pattern^#?(?:[A-Fa-f0-9]{3}|[A-Fa-f0-9]{6})$

    Flags: none

    Matching example
    #09aBcF
    Limitation
    Does not match 4- or 8-digit alpha forms, CSS variables, or named colors.

Was this tool helpful?