regex.reez.cc

regex --library

Regex library

31 patterns for things you would otherwise look up again. Each one is checked against the examples next to it on every build, and each says where it stops being reliable.

31 patterns

Web

Email address

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

Something, an @, a domain with a dot. Deliberately loose.

  • matches: ada@example.com
  • matches: first.last+tag@mail.example.org
  • does not match: ada@example
  • does not match: @example.com
  • does not match: ada lovelace@example.com

No pattern can tell whether a mailbox exists. Use this to catch typos, then send a confirmation mail.

URL (http, https)

/^https?:\/\/[^\s/$.?#][^\s]*$/i

A web address with scheme. Anything without spaces may follow the host.

  • matches: https://reez.cc
  • matches: http://localhost:4321/path?q=1#top
  • does not match: ftp://example.com
  • does not match: https://
  • does not match: //example.com/path

Domain name

/^(?=.{1,253}$)(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,63}$/i

Labels of letters, digits and hyphens, no hyphen at the start or end of a label, at most 253 characters.

  • matches: reez.cc
  • matches: sub.example.co.uk
  • matches: xn--mnchen-3ya.de
  • does not match: -bad.example
  • does not match: example
  • does not match: under_score.example

IPv4 address

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

Four numbers from 0 to 255, no leading zeros.

  • matches: 192.168.0.1
  • matches: 8.8.8.8
  • matches: 255.255.255.255
  • does not match: 256.1.1.1
  • does not match: 1.2.3
  • does not match: 01.2.3.4

IPv6 address

/^(?:(?:[0-9a-f]{1,4}:){7}[0-9a-f]{1,4}|(?:[0-9a-f]{1,4}:){1,7}:|(?:[0-9a-f]{1,4}:){1,6}:[0-9a-f]{1,4}|(?:[0-9a-f]{1,4}:){1,5}(?::[0-9a-f]{1,4}){1,2}|(?:[0-9a-f]{1,4}:){1,4}(?::[0-9a-f]{1,4}){1,3}|(?:[0-9a-f]{1,4}:){1,3}(?::[0-9a-f]{1,4}){1,4}|(?:[0-9a-f]{1,4}:){1,2}(?::[0-9a-f]{1,4}){1,5}|[0-9a-f]{1,4}:(?::[0-9a-f]{1,4}){1,6}|:(?:(?::[0-9a-f]{1,4}){1,7}|:))$/i

Eight groups of hex digits, with :: standing in for one run of zero groups.

  • matches: 2001:0db8:85a3:0000:0000:8a2e:0370:7334
  • matches: 2001:db8::8a2e:370:7334
  • matches: ::1
  • matches: ::
  • does not match: 2001:db8:::1
  • does not match: 12345::1
  • does not match: 1:2:3:4:5:6:7

Does not cover the mixed form with an IPv4 tail (::ffff:192.0.2.1) or zone ids (%eth0).

MAC address

/^[0-9a-f]{2}([:-])(?:[0-9a-f]{2}\1){4}[0-9a-f]{2}$/i

Six hex pairs. The backreference makes sure the same separator is used throughout.

  • matches: 00:1A:2b:3C:4d:5E
  • matches: 00-1a-2b-3c-4d-5e
  • does not match: 00:1a:2b:3c:4d
  • does not match: 00:1a-2b:3c:4d:5e
  • does not match: 0g:1a:2b:3c:4d:5e

URL slug

/^[a-z0-9]+(?:-[a-z0-9]+)*$/

Lowercase letters and digits, single hyphens between words.

  • matches: hello-world
  • matches: v2
  • matches: regex-tester-2026
  • does not match: Hello-World
  • does not match: -leading
  • does not match: double--dash

Hex color

/^#(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i

CSS hex colors with 3, 4, 6 or 8 digits.

  • matches: #0f4
  • matches: #00ff41
  • matches: #00FF4180
  • does not match: #00ff4
  • does not match: 00ff41
  • does not match: #ggg

Password rules

/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{12,}$/

At least 12 characters with a lowercase letter, an uppercase letter and a digit. One lookahead per rule.

  • matches: Correct-Horse-9
  • matches: aB3aB3aB3aB3
  • does not match: correct-horse-battery
  • does not match: Short1
  • does not match: ALLUPPERCASE123

Length protects better than character rules. If you can choose the policy, ask for length.

Numbers

Integer

/^-?(?:0|[1-9]\d*)$/

Whole number with optional minus, no leading zeros.

  • matches: 0
  • matches: -42
  • matches: 1234567890
  • does not match: 007
  • does not match: 1.5
  • does not match: +1
  • does not match: --1

Decimal number

/^-?(?:0|[1-9]\d*)(?:\.\d+)?$/

Integer with an optional fraction after a dot.

  • matches: 3.14
  • matches: -0.5
  • matches: 10
  • does not match: .5
  • does not match: 1.
  • does not match: 1,5

Number with exponent

/^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?$/

The number grammar of JSON: optional fraction, optional exponent.

  • matches: 6.022e23
  • matches: -1E-9
  • matches: 42
  • does not match: 1e
  • does not match: e5
  • does not match: 0x10

Number with thousands separators

/^-?\d{1,3}(?:,\d{3})+(?:\.\d+)?$/

Groups of three digits separated by commas, optional fraction.

  • matches: 1,234,567.89
  • matches: 12,000
  • matches: -999,999
  • does not match: 1,23
  • does not match: 12,3456
  • does not match: ,123
  • does not match: 1234

Hex number

/^(?:0x)?[0-9a-f]+$/i

Hex digits with an optional 0x prefix.

  • matches: 0xFF
  • matches: deadbeef
  • matches: 0
  • does not match: 0x
  • does not match: xyz
  • does not match: 12g

Semantic version

/^(?<major>0|[1-9]\d*)\.(?<minor>0|[1-9]\d*)\.(?<patch>0|[1-9]\d*)(?:-(?<pre>[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+(?<build>[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$/

major.minor.patch with optional pre-release and build metadata, each part as a named group.

  • matches: 1.0.0
  • matches: 2.3.1-beta.2
  • matches: 1.0.0-rc.1+build.5
  • does not match: 1.0
  • does not match: 01.2.3
  • does not match: 1.2.3-
  • does not match: v1.2.3

Slightly looser than the spec: numeric pre-release parts may have leading zeros.

Dates and time

ISO date

/^\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])$/

YYYY-MM-DD with month 01 to 12 and day 01 to 31.

  • matches: 2026-11-14
  • matches: 1999-01-31
  • does not match: 2026-13-01
  • does not match: 2026-00-10
  • does not match: 2026-1-5
  • does not match: 14.11.2026

Accepts 2026-02-31. A pattern cannot know the calendar; parse the date in code to be sure.

Time (24 hours)

/^(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d)?$/

HH:MM with optional seconds.

  • matches: 09:30
  • matches: 23:59:59
  • matches: 00:00
  • does not match: 24:00
  • does not match: 9:30
  • does not match: 12:60

ISO 8601 timestamp

/^\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])T(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d+)?(?:Z|[+-](?:[01]\d|2[0-3]):[0-5]\d)$/

Date, T, time, optional fraction of a second, then Z or a UTC offset. The shape of Date.toISOString().

  • matches: 2026-11-14T19:03:42Z
  • matches: 2026-11-14T20:03:42.123+01:00
  • does not match: 2026-11-14 19:03:42
  • does not match: 2026-11-14T19:03:42
  • does not match: 2026-11-14T25:00:00Z

Date, day.month.year

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

The format used in Germany and much of Europe, with or without leading zeros.

  • matches: 14.11.2026
  • matches: 1.2.2026
  • does not match: 32.01.2026
  • does not match: 14.13.2026
  • does not match: 14/11/2026

Text

Repeated words

/\b(\w+)\s+\1\b/gi

The same word twice in a row. Replace with $1 to remove the copy.

This is is a test of the the regex tester. Nothing wrong here.

Trailing whitespace

/[ \t]+$/gm

Spaces and tabs at the end of a line. Replace with nothing to clean up.

clean line trailing spaces tab at the end last line

Blank lines

/^[ \t]*\r?\n/gm

Lines that are empty or hold only spaces. Replace with nothing to remove them.

first second

Quoted string with escapes

/"(?:[^"\\]|\\.)*"/g

Double-quoted text in which \" does not end the string.

say "hello", then "a \"quoted\" word" and "".

camelCase word breaks

/(?<=[a-z0-9])(?=[A-Z])/g

The empty positions where a new word starts. Replace with a space, - or _ to split an identifier.

parseHttpResponse2Json

Code

UUID

/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i

Versions 1 to 8 in the usual 8-4-4-4-12 form.

  • matches: 123e4567-e89b-42d3-a456-426614174000
  • matches: 018F4E7A-9B2C-7D3E-8F10-A1B2C3D4E5F6
  • does not match: 123e4567-e89b-02d3-a456-426614174000
  • does not match: 123e4567e89b42d3a456426614174000
  • does not match: 123e4567-e89b-42d3-a456

JWT shape

/^[A-Za-z0-9_-]{2,}\.[A-Za-z0-9_-]{2,}\.[A-Za-z0-9_-]*$/

Three base64url parts separated by dots. Checks the shape only, not the signature.

  • matches: eyJhbGciOiJub25lIn0.eyJzdWIiOiJkZW1vIn0.c2lnbmF0dXJl
  • matches: eyJhbGciOiJub25lIn0.eyJzdWIiOiJkZW1vIn0.
  • does not match: only.two
  • does not match: has space.in.it
  • does not match: a+b.c/d.e=

HTML tag

/<\/?([a-z][a-z0-9-]*)\b[^>]*>/gi

Opening, closing and self-closing tags, with the tag name in group 1.

<p class="lead">Hi <br/> there</p>

Fine for a quick search. Do not parse HTML with it: a > inside an attribute value ends the match early.

Line comment

/(?<!:)\/\/.*$/gm

From // to the end of the line. The lookbehind skips the // in URLs.

const port = 8080; // default const url = "https://reez.cc"; // home

Does not know about strings: a // inside quotes that is not part of a URL still matches.

Block comment

/\/\*[\s\S]*?\*\//g

From /* to the next */, across lines. The lazy quantifier stops at the first */.

/* one */ code(); /* two lines */ more();

KEY=value line

/^([A-Z_][A-Z0-9_]*)=(.*)$/gm

Lines of a .env file, with the name in group 1 and the value in group 2.

PORT=8080 # comment DEBUG= lower=ignored

More