Back to News & Insights
JavaScript October 10, 2026 · 7 min read

30 Practical JavaScript Regex Patterns With Examples and Tests

Regular expressions are useful for input validation, text extraction, log analysis, and everyday...

30 Practical JavaScript Regex Patterns With Examples and Tests

Regular expressions are useful for input validation, text extraction, log analysis, and everyday JavaScript development. But copying a regex from the internet without understanding its limitations can create unexpected bugs.

This guide brings together 30 practical JavaScript regex patterns, explains what they do, and shows how to test them.

You can also explore the open-source DevToolkit Regex Pattern Library, which contains 32 documented patterns, or experiment with the free online Regex Tester. Input validation patterns Email address

Useful for basic email formatting checks. It is not a complete email validator and cannot confirm whether an email address exists. HTTP or HTTPS URL

Checks for an HTTP or HTTPS prefix followed by non-whitespace characters. Use JavaScript's URL class for more comprehensive URL parsing. Hexadecimal color

Supports three- and six-digit hexadecimal colors, but not eight-digit colors with alpha channels. Lowercase URL slug

Useful for validating lowercase URL slugs without spaces or repeated hyphens. Alphanumeric string

Accepts ASCII letters and digits only. Unicode letters are excluded. Signed integer

Useful for decimal input formats. It does not support scientific notation or locale-specific separators. US ZIP code

Checks ZIP code format, not whether the postal code actually exists. Networking patterns IPv4 address

Validates four decimal octets between 0 and 255. It does not identify reserved or private addresses. Basic IPv6 address

This pattern intentionally handles only fully expanded IPv6 addresses. Compressed IPv6 notation requires a more complete validator. MAC address

Checks a common MAC address layout. It does not confirm that the address belongs to a real device. Hostname

Checks ASCII hostname labels, but does not perform a DNS lookup. TCP/UDP port number

Accepts decimal integers from 0 through 65535. It does not check whether a port is available. Dates, times, and identifiers UUID version 4

This checks the UUID layout, version and variant bits. It cannot prove uniqueness. ISO-style calendar date

Important: 2026-99-99 also matches because the expression checks the format, not calendar validity. 24-hour time

Validates time in HH:MM format without seconds or time zones. ISO-style date-time with timezone

Want to discuss this further?

Book a free strategy call with our team to see how these insights apply to your specific business goals.

Book a consultation