Regex Tester & Library

Test, explain and share JavaScript regular expressions with live highlighting, then start from a practical pattern below. Every recipe lists its gotchas so you know when not to use it.

Regex sandbox

Running…

Tip Hover or place the caret in the expression or the text to inspect tokens and matches.

235 characters

Pattern library

Practical regular expressions and find-and-replace recipes, shared with the site-wide reference data. Open any of them in the sandbox above.

Showing 8 of 8 patterns. Search and filters are shareable by URL.

Regex

Email Address

Matches most common email address formats for basic input filtering.

Use this for a lightweight format check, not proof that an address exists or can receive mail.

Find

[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}
Regex

URL

Matches standard HTTP and HTTPS URLs in common text.

Useful for finding likely web URLs in text; use a URL parser when you need semantic validation.

Find

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

ISO 8601 Date

Matches a date in YYYY-MM-DD format.

Use this for the basic shape of an ISO calendar date, then parse it to verify that the day exists.

Find

^\d{4}-\d{2}-\d{2}$
Regex Replace recipe

Slugify Text

Finds runs of non-alphanumeric characters so they can be replaced with hyphens.

Use with a lowercase transform and trim step to turn ordinary text into URL-friendly slugs.

Find

[^a-z0-9]+

Replace

-
Regex

Markdown Heading

Matches Markdown heading lines from level one through six.

Use this to find ATX-style Markdown headings in editors and content-processing scripts.

Find

^#{1,6}\s+.*$
Regex

Remove HTML Tags

Matches HTML-looking tags for simple text cleanup.

Use only for simple cleanup of trusted, predictable markup; use an HTML parser for real sanitization or transformation.

Find

<[^>]*>
Regex

IPv4 Address

Matches valid dotted-decimal IPv4 addresses such as 192.168.1.1.

Use word boundaries so the pattern finds addresses inside longer text without matching fragments of bigger numbers.

Find

\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b
Regex Replace recipe

BibTeX Entry Extractor

Captures the entry type, citation key, and body of a BibTeX record to normalize or repair it.

Normalizes mixed brace and parenthesis entries into the standard @type{key, body} form with a find-and-replace.

Find

@(\w+)\s*[{(]([^,\s]+)\s*,([\s\S]*?)[})]

Replace

@$1{$2,$3}