Sign in Start free

Regex pattern library

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.

52 patterns

Multiple spaces to one (replace)

{2,}

Finds two or more spaces in a row; replace with a single space.

Text Cleanup JavaScript /g 1 views ▲ 0

CSV fields (quoted values)

(?:^|,)(?:"((?:[^"]|"")*)"|([^,]*))

Splits one CSV line into fields, handling quoted fields with commas and doubled quotes. Group 1 = quoted content, group 2 = plain field.

Code & Data JavaScript /g 1 views ▲ 0

.env / properties lines

^\s*([A-Za-z_][\w.]*)\s*=\s*"?([^"\n]*)"?\s*$

KEY=value lines; group 1 is the key, group 2 the value (quotes not included). Comments and blank lines are skipped.

Code & Data JavaScript /gm 1 views ▲ 0

camelCase to snake_case (replace)

([a-z\d])([A-Z])

Inserts an underscore before each capital letter that follows a lowercase letter or digit. Replace with "$1_$2" and lowercase the result in code.

Code & Data JavaScript /g 1 views ▲ 0

Hexadecimal literal

\b0[xX][\da-fA-F]+\b

0x-prefixed hexadecimal numbers like 0xFF and 0x1a2b.

Code & Data JavaScript /g 1 views ▲ 0

JavaScript / Java / C comments

\/\/.*|\/\*[\s\S]*?\*\/

Line comments (// …) and block comments (/* … */, across lines).

Code & Data JavaScript /g 1 views ▲ 0

JSON / JavaScript string literal

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

Double-quoted strings with escaped characters inside (\" \\ \n …). Group 1 is the content.

Code & Data JavaScript /g 1 views ▲ 0

Semantic version

\bv?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([\da-zA-Z-]+(?:\.[\da-zA-Z-]+)*))?(?:\+([\da-zA-Z-]+(?:\.[\da-zA-Z-]+)*))?\b

MAJOR.MINOR.PATCH with optional pre-release and build metadata, from the semver.org specification (simplified).

Code & Data JavaScript /g 1 views ▲ 0

UUID / GUID

\b[\da-fA-F]{8}-[\da-fA-F]{4}-[1-8][\da-fA-F]{3}-[89abAB][\da-fA-F]{3}-[\da-fA-F]{12}\b

Version 1–8 UUIDs in the canonical 8-4-4-4-12 form, any case.

Code & Data JavaScript /g 1 views ▲ 0

US phone number

(?:\+1[ .-]?)?\(?([2-9]\d{2})\)?[ .-]?(\d{3})[ .-]?(\d{4})\b

(415) 555-2671, 415-555-2671, 415.555.2671 and +1 415 555 2671.

Validation JavaScript /g 1 views ▲ 0

International phone number (E.164)

^\+[1-9]\d{6,14}$

A plus sign followed by up to 15 digits, the format used by most SMS and telephony APIs.

Validation JavaScript /gm 1 views ▲ 0

Username

^[A-Za-z][\w.]{1,14}[A-Za-z\d_]$

3 to 16 characters: letters, digits, underscores and dots; must start with a letter and cannot end with a dot.

Validation JavaScript /gm 1 views ▲ 0

Credit card number (format only)

\b(?:4\d{3}|5[1-5]\d{2}|2[2-7]\d{2})(?:[ -]?\d{4}){3}\b|\b3[47]\d{2}[ -]?\d{6}[ -]?\d{5}\b

Visa, Mastercard and American Express number formats with optional spaces or dashes. Checks the shape only – use the Luhn checksum in code.

Validation JavaScript /g 1 views ▲ 0

Percentage

\b(?:100(?:\.0+)?|\d{1,2}(?:\.\d+)?)%

Numbers from 0 to 100 followed by a percent sign, decimals allowed.

Numbers & Money JavaScript /g 1 views ▲ 0

Price in dollars

\$\d{1,3}(?:,\d{3})*(?:\.\d{2})?\b

$5, $1,000, $12.99 – optional thousands separators and cents.

Numbers & Money JavaScript /g 1 views ▲ 0

Add thousands separators (replace)

\B(?=(\d{3})+(?!\d))

Substitution trick: inserts a comma before every group of three digits that is followed only by more groups of three. Use the Substitution function with replacement ",".

Numbers & Money JavaScript /g 1 views ▲ 0

Number with thousands separators

\b\d{1,3}(?:,\d{3})*(?:\.\d+)?\b

1,234,567.89 style numbers: groups of three digits separated by commas, optional decimals.

Numbers & Money JavaScript /g 1 views ▲ 0

Decimal number

[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?

Numbers with optional sign, decimals and exponent, like 3.14, -0.5, .5 and 6.02e23.

Numbers & Money JavaScript /g 1 views ▲ 0

Integer (signed)

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

Whole numbers with an optional sign, no leading zeros.

Numbers & Money JavaScript /gm 1 views ▲ 0

ISO 8601 date-time

\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:?\d{2})?

2026-11-12T08:30:00Z style timestamps with optional fraction and time zone offset.

Dates & Times JavaScript /g 1 views ▲ 0

Time 12-hour with AM/PM

\b(1[0-2]|0?[1-9]):([0-5]\d)\s?([AaPp][Mm])\b

1:00 to 12:59 followed by am/pm in any case, with or without a space.

Dates & Times JavaScript /g 1 views ▲ 0

Time 24-hour HH:MM(:SS)

\b([01]\d|2[0-3]):([0-5]\d)(?::([0-5]\d))?\b

Times from 00:00 to 23:59 with optional seconds.

Dates & Times JavaScript /g 1 views ▲ 0

Date DD/MM/YYYY

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

Day/month/year dates with / . or - separators (the same separator twice, checked with a back reference).

Dates & Times 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