/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/Checks for a practical email shape with one @ and a dot in the domain.
Examples and limitations
Matches: dev@example.com
Does not match: dev@example
Limitations: This is intentionally pragmatic, not a complete RFC email parser; it does not verify that the address exists.
HTTP or HTTPS URL
Validation/^https?:\/\/[^\s]+$/iRequires an HTTP or HTTPS scheme followed by at least one non-space character.
Examples and limitations
Matches: https://example.com/docs?q=1
Does not match: example.com/docs
Limitations: It does not validate every URL rule or confirm that the host is reachable.
/^(?:(?:25[0-5]|2[0-4]\d|1?\d?\d)\.){3}(?:25[0-5]|2[0-4]\d|1?\d?\d)$/Validates four decimal octets, each in the range 0–255.
Examples and limitations
Matches: 192.168.1.10
Does not match: 192.168.1.300
Limitations: It does not distinguish private, loopback, multicast, or reserved address ranges.
Basic IPv6 address
Networking/^(?:[0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4}$/Matches the fully expanded eight-group IPv6 notation.
Examples and limitations
Matches: 2001:0db8:0000:0000:0000:ff00:0042:8329
Does not match: 2001:db8::1
Limitations: This educational pattern does not support compressed (::), IPv4-mapped, or zone-indexed IPv6 forms.
/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iChecks the UUID layout plus the version 4 and RFC variant bits.
Examples and limitations
Matches: 550e8400-e29b-41d4-a716-446655440000
Does not match: 550e8400-e29b-11d4-a716-446655440000
Limitations: It validates format and bits only; it cannot prove uniqueness or how the UUID was generated.
Hexadecimal color
Validation/^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/iAccepts CSS-style three- or six-digit hexadecimal colors with a leading #.
Examples and limitations
Matches: #0ea5e9
Does not match: 0ea5e9
Limitations: It excludes alpha forms such as #RRGGBBAA and functional color notation.
ISO calendar date
Dates and times/^\d{4}-\d{2}-\d{2}$/Checks the YYYY-MM-DD shape used by ISO-style dates.
Examples and limitations
Matches: 2026-10-11
Does not match: 11/10/2026
Limitations: It checks shape, not calendar validity; values such as 2026-99-99 still match.
24-hour time
Dates and times/^(?:[01]\d|2[0-3]):[0-5]\d$/Matches hours from 00–23 and minutes from 00–59 in HH:MM format.
Examples and limitations
Matches: 23:45
Does not match: 24:00
Limitations: Seconds, time zones, and leap seconds are not included.
/^[+-]?\d+$/Accepts an optional sign followed by one or more decimal digits.
Examples and limitations
Matches: -42
Does not match: 3.14
Limitations: It does not enforce a numeric range and accepts leading zeroes.
/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)$/Matches signed whole numbers and decimal values such as 12.5 or .5.
Examples and limitations
Matches: -12.50
Does not match: 1,000.00
Limitations: Scientific notation, locale separators, and numeric range are not supported.
Lowercase URL slug
Validation/^[a-z0-9]+(?:-[a-z0-9]+)*$/Allows lowercase words or numbers separated by single hyphens.
Examples and limitations
Matches: regex-cheat-sheet
Does not match: Regex Cheat Sheet
Limitations: Whether a slug is unique or appropriate for a specific route must be checked separately.
ASCII alphanumeric string
Validation/^[A-Za-z0-9]+$/Requires one or more ASCII letters or digits and no punctuation or spaces.
Examples and limitations
Matches: Build2026
Does not match: Build-2026
Limitations: Unicode letters and underscores are intentionally excluded.
Whitespace run
Text processing/\s+/gFinds one or more whitespace characters, including spaces, tabs, and line breaks.
Examples and limitations
Matches: hello world
Does not match: helloworld
Limitations: Whitespace semantics vary by engine and flags; this targets JavaScript behavior.
Duplicate spaces
Text processing/ {2,}/gFinds two or more literal consecutive spaces for cleanup.
Examples and limitations
Matches: Too many spaces
Does not match: One space
Limitations: It does not match tabs or newlines; use \s{2,} when those should count.
HTML-like tag
Text processing/<\/?[A-Za-z][^>]*>/gFinds text shaped like an opening or closing HTML tag.
Examples and limitations
Matches: <section class="hero">
Does not match: 2 < 3
Limitations: Do not use regex as an HTML parser; nested structure, quoted > characters, and malformed markup need a parser.
JavaScript-style identifier
Programming/^[A-Za-z_$][A-Za-z0-9_$]*$/Checks the common ASCII shape of a JavaScript identifier.
Examples and limitations
Matches: user_$1
Does not match: 1stUser
Limitations: It does not reject reserved words and does not cover all Unicode identifier rules.
Double-quoted string
Text processing/"(?:\\.|[^"\\])*"/gFinds double-quoted strings while allowing escaped characters inside them.
Examples and limitations
Matches: "hello \"world\""
Does not match: 'hello'
Limitations: It is not a full language lexer and may not handle every multiline or templating syntax.
Common log level
Programming/\b(?:TRACE|DEBUG|INFO|WARN|ERROR|FATAL)\b/giFinds common severity labels in application logs.
Examples and limitations
Matches: 2026-10-11 INFO Request complete
Does not match: NOTICE Request complete
Limitations: Log formats and level names differ between systems.
Common access-log line
Programming/^\S+ \S+ \S+ \[[^\]]+\] "(?:[^"\\]|\\.)*" \d{3} \d+(?: "[^"]*" "[^"]*")?$/Matches the broad shape of a Common Log Format or combined access-log line.
Examples and limitations
Matches: 127.0.0.1 - - [11/Oct/2026:10:20:30 +0000] "GET / HTTP/1.1" 200 1234
Does not match: GET / returned okay
Limitations: It checks line shape, not whether methods, dates, status codes, or quoted fields are semantically valid.
Semantic version
Programming/^v?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/Matches the core and optional prerelease/build portions of Semantic Versioning 2.0.
Examples and limitations
Matches: v1.4.0-beta.2
Does not match: 1.4
Limitations: It does not compare versions or enforce project-specific release rules.
/^(?:[0-9A-Fa-f]{2}[:-]){5}[0-9A-Fa-f]{2}$/Accepts six hexadecimal octets separated by colons or hyphens.
Examples and limitations
Matches: 00:1A:2B:3C:4D:5E
Does not match: 00:1A:2B:3C:4D
Limitations: It does not identify vendor prefixes or guarantee that the address is assigned to a device.
/^(?=.{1,253}$)(?:[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?\.)*[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?$/Checks labels, hyphen placement, and the maximum hostname length.
Examples and limitations
Matches: api.example.com
Does not match: -api.example.com
Limitations: It does not validate DNS resolution, IDN display names, or every application-specific host rule.
TCP or UDP port
Networking/^(?:\d|[1-9]\d{1,3}|[1-5]\d{4}|6[0-4]\d{3}|65[0-4]\d{2}|655[0-2]\d|6553[0-5])$/Matches an integer from 0 through 65535.
Examples and limitations
Matches: 443
Does not match: 70000
Limitations: It does not show whether a port is open or assigned to a particular service.
Absolute Unix path
Programming/^\/(?:[^\0\n\/]+\/)*[^\0\n\/]*$/Checks a slash-prefixed path without null bytes or newline characters.
Examples and limitations
Matches: /var/log/app.log
Does not match: var/log/app.log
Limitations: Filesystem rules differ by operating system, permissions, and normalization requirements.
JSON string token
Programming/"(?:\\(?:["\\\/bfnrt]|u[0-9A-Fa-f]{4})|[^"\\\u0000-\u001F])*"/Matches a JSON string token with valid escape forms and no raw control characters.
Examples and limitations
Matches: "line\nvalue"
Does not match: "unescaped
line"
Limitations: A token match does not validate a complete JSON document; use a JSON parser for that.
/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/Checks the standard padded Base64 alphabet and grouping.
Examples and limitations
Matches: SGVsbG8=
Does not match: SGVsbG8!
Limitations: It does not decode the value or distinguish arbitrary binary data from text.
Hexadecimal number
Programming/^(?:0x)?[0-9A-Fa-f]+$/iAccepts hexadecimal digits with an optional 0x prefix.
Examples and limitations
Matches: 0xFF00AA
Does not match: 0xGHI
Limitations: It does not enforce a numeric width or range.
US phone number
Validation/^(?:\+1[ .-]?)?(?:\(?[2-9]\d{2}\)?[ .-]?)?[2-9]\d{2}[ .-]?\d{4}$/Accepts common North American phone formats with an optional country code.
Examples and limitations
Matches: +1 (415) 555-0132
Does not match: 123-45-6789
Limitations: Phone numbering plans are complex; this does not verify assignment or support every international format.
/^\d{5}(?:-\d{4})?$/Matches five-digit ZIP codes and optional four-digit extensions.
Examples and limitations
Matches: 94105-1234
Does not match: 9410
Limitations: It checks format only and does not confirm that the ZIP code exists.
ISO date-time prefix
Dates and times/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/Matches an ISO-like date-time with seconds and an explicit UTC offset.
Examples and limitations
Matches: 2026-10-11T14:30:00Z
Does not match: 2026/10/11 14:30:00
Limitations: Calendar validity and leap seconds are not checked.
Simple duration
Dates and times/^(?:\d+(?:\.\d+)?)(?:ms|s|m|h|d)$/iMatches a positive numeric duration with a common unit.
Examples and limitations
Matches: 2.5h
Does not match: two hours
Limitations: It does not convert units or accept compound durations such as 1h 30m.
Quoted CSV field
Text processing/^"(?:""|[^"])*"$/Validates one quoted CSV field and permits doubled double-quotes inside it.
Examples and limitations
Matches: "two, too"
Does not match: "unterminated
Limitations: CSV dialects vary; this checks one quoted field only and does not parse a complete row.