Sign in Start free

Web & URLs patterns

Tested regular expressions you can open in the tester, read the explanation of and adapt. Each pattern comes with sample text and unit tests. Save your own pattern with Save & share and tick “publish” to add it here.

8 patterns

★CSS hex color

#((?:[\da-fA-F]{3}){1,2}|(?:[\da-fA-F]{4}){1,2})\b

#RGB, #RGBA, #RRGGBB and #RRGGBBAA colors. Group 1 holds the hex digits.

Web & URLs JavaScript /g 1 views ▲ 0

★IPv4 address

\b(?:(?: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)\b

Matches dotted IPv4 addresses with every octet between 0 and 255 – 256.1.1.1 or 1.2.3 do not match.

Web & URLs JavaScript /g 1 views ▲ 0

★URL (http / https)

https?:\/\/(?:www\.)?[-\w@:%.+~#=]{1,256}\.[a-zA-Z\d()]{1,6}\b(?:[-\w()@:%+.~#?&/=]*[\w/])?

Finds web addresses starting with http:// or https:// including port, path, query string and fragment. Stops before trailing punctuation like a closing parenthesis or full stop.

Web & URLs JavaScript /g 1 views ▲ 0

Query string parameters

[?&]([^=&#]+)=([^&#]*)

Splits a URL query string into name (group 1) and value (group 2) pairs.

Web & URLs JavaScript /g 1 views ▲ 0

HTML tags (open, close, self-closing)

<\/?([a-zA-Z][\w-]*)\b[^>]*>

Finds HTML tags and captures the tag name in group 1. For extracting tags from snippets – use a real HTML parser for whole documents.

Web & URLs JavaScript /g 1 views ▲ 0

URL slug

^[a-z\d]+(?:-[a-z\d]+)*$

Lowercase words separated by single hyphens, as used in pretty URLs.

Web & URLs JavaScript /gm 1 views ▲ 0

Domain name

\b(?:[a-zA-Z\d](?:[a-zA-Z\d-]{0,61}[a-zA-Z\d])?\.)+[a-zA-Z]{2,}\b

A host name with at least one dot and a top-level domain of 2+ letters. Labels may contain hyphens but not start or end with one.

Web & URLs JavaScript /g 1 views ▲ 0

IPv6 address

(?:[\da-fA-F]{1,4}:){7}[\da-fA-F]{1,4}|(?:[\da-fA-F]{1,4}:){1,7}:|(?:[\da-fA-F]{1,4}:){1,6}:[\da-fA-F]{1,4}|(?:[\da-fA-F]{1,4}:){1,5}(?::[\da-fA-F]{1,4}){1,2}|(?:[\da-fA-F]{1,4}:){1,4}(?::[\da-fA-F]{1,4}){1,3}|(?:[\da-fA-F]{1,4}:){1,3}(?::[\da-fA-F]{1,4}){1,4}|(?:[\da-fA-F]{1,4}:){1,2}(?::[\da-fA-F]{1,4}){1,5}|[\da-fA-F]{1,4}:(?::[\da-fA-F]{1,4}){1,6}|:(?:(?::[\da-fA-F]{1,4}){1,7}|:)

Matches full and compressed IPv6 addresses (::1, fe80::1ff:fe23:4567:890a, 2001:db8::8a2e:370:7334).

Web & URLs JavaScript /g 1 views ▲ 0