Regex Snippets

A curated collection of common regular expressions for developers. Copy, paste, and ship faster.

Email Address

validationweb

Standard email validation pattern matching most common addresses.

Regex Pattern
^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$
Matches (Example)
user@example.com
Nexsa Code Bit

URL (HTTP/HTTPS)

validationweb

Matches standard URLs starting with http or https.

Regex Pattern
https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)
Matches (Example)
https://nexsa.convert/tools
Nexsa Code Bit

Phone Number

validationtelecom

Validation for India phone numbers.

Select Country
Test Validator
Regex Pattern
^(\+91[\-\s]?)?[0]?(91)?[6789]\d{9}$
Nexsa Code Bit

Strong Password

securityvalidation

Min 8 chars, 1 upper, 1 lower, 1 number, and 1 special character.

Regex Pattern
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$
Matches (Example)
P@ssw0rd123!
Nexsa Code Bit

JWT Token

securityauth

Validates the structure of a JSON Web Token.

Regex Pattern
^[A-Za-z0-9-_=]+\.[A-Za-z0-9-_=]+\.?[A-Za-z0-9-_.+/=]*$
Matches (Example)
eyJhbGci...SflKxwRJSMe...
Nexsa Code Bit

IPv4 Address

networkvalidation

Validates standard IPv4 network addresses.

Regex Pattern
^(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}$
Matches (Example)
192.168.1.1
Nexsa Code Bit

IPv6 Address

networkvalidation

Standard IPv6 address validation.

Regex Pattern
(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4})
Matches (Example)
2001:0db8:85a3:0000:0000:8a2e:0370:7334
Nexsa Code Bit

MAC Address

networkhardware

Validates standard 48-bit hardware MAC addresses.

Regex Pattern
^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$
Matches (Example)
01:23:45:67:89:AB
Nexsa Code Bit

Hex Color

designweb

Matches both 3 and 6 digit CSS hex color codes.

Regex Pattern
^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$
Matches (Example)
#4f46e5
Nexsa Code Bit

Slug (URL Friendly)

webseo

Lowercase alphanumeric strings separated by hyphens.

Regex Pattern
^[a-z0-9]+(?:-[a-z0-9]+)*$
Matches (Example)
my-blog-post-title
Nexsa Code Bit

YouTube URL

webvideo

Extracts the video ID from common YouTube URL formats.

Regex Pattern
(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/watch\?v=|youtu\.be\/)([a-zA-Z0-9_-]{11})
Matches (Example)
https://youtube.com/watch?v=dQw4w9WgXcQ
Nexsa Code Bit

GitHub Repository

webdev

Matches standard GitHub repository URLs.

Regex Pattern
https?:\/\/github\.com\/[\w-]+\/[\w.-]+
Matches (Example)
https://github.com/nexsa/convert
Nexsa Code Bit

Ethereum Address

cryptoweb3

Validates standard Ethereum (ETH) wallet addresses.

Regex Pattern
^0x[a-fA-F0-9]{40}$
Matches (Example)
0x71C7656EC7ab88b098defB751B7401B5f6d8976F
Nexsa Code Bit

CamelCase

codenaming

Matches standard lower camelCase naming convention.

Regex Pattern
^[a-z]+([A-Z][a-z0-9]+)*$
Matches (Example)
myAwesomeFunction
Nexsa Code Bit

PascalCase

codenaming

Matches standard PascalCase naming convention.

Regex Pattern
^[A-Z][a-z0-9]+([A-Z][a-z0-9]+)*$
Matches (Example)
NexsaComponent
Nexsa Code Bit

Base64 String

securitydata

Validates if a string is a valid Base64 encoded format.

Regex Pattern
^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$
Matches (Example)
TmV4dXNDb252ZXJ0
Nexsa Code Bit

Price (Currency)

financeformatting

Matches currency formats like $1,234.56.

Regex Pattern
^\$?(\d{1,3}(\,\d{3})*|(\d+))(\.\d{2})?$
Matches (Example)
$1,499.00
Nexsa Code Bit

Digits Only

validationdata

Matches a string containing only numerical digits.

Regex Pattern
^\d+$
Matches (Example)
90210
Nexsa Code Bit

Credit Card

financevalidation

Generic pattern for Visa, MasterCard, and Discover.

Regex Pattern
^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12})$
Matches (Example)
4111 2222 3333 4444
Nexsa Code Bit

Date (YYYY-MM-DD)

formattingdate

Strict ISO 8601 date format validation.

Regex Pattern
^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$
Matches (Example)
2023-12-31
Nexsa Code Bit

Handlebars Tags

codetemplating

Detects double mustache/handlebars template tags.

Regex Pattern
\{\{\s*[\w\.]+\s*\}\}
Matches (Example)
{{ user.name }}
Nexsa Code Bit

Remove HTML Tags

textextraction

Matches any HTML tag for stripping/removal.

Regex Pattern
<[^>]*>
Matches (Example)
<div>Hello</div> -> Hello
Nexsa Code Bit

Time (24h)

formattingtime

Matches 24-hour time format (HH:MM).

Regex Pattern
^([01]?[0-9]|2[0-3]):[0-5][0-9]$
Matches (Example)
23:59
Nexsa Code Bit

SSN (US)

validationidentity

Standard US Social Security Number format.

Regex Pattern
^\d{3}-\d{2}-\d{4}$
Matches (Example)
000-00-0000
Nexsa Code Bit

Mathematics of Pattern Matching

Regular Expressions (RegEx) are the most efficient way to perform complex search and validation logic. From simple string matching to complex Lookahead and Lookbehind assertions, NexsaConvert provides optimized, high-performance patterns for every digital environment.

Expert Implementation

Greedy vs. Lazy Matching Logic

A common pitfall in Regex is catastrophic backtracking caused by excessive greedy quantifiers. Our snippets are handcrafted to prioritize performance, utilizing non-capturing groups and atomized logic to ensure your validation runs in O(n) time whenever possible.

Regex Specs

EnginePCRE-JS-Flavor
SecurityReDoS-Resistant
StandardPOSIX-Compliant

Regex Expert FAQs

What does `.*?` mean?

The `?` after a quantifier makes it 'lazy'. It will match as little as possible. Without the `?`, `.*` is greedy and will match everything until the very last possible character.

What is a Lookahead assertion?

Lookaheads (`(?=...)`) allow you to check if a pattern exists ahead in the string without actually consuming the characters. Perfect for password validation requiring multiple conditions.

How do I prevent ReDoS attacks?

Avoid 'nested quantifiers' (e.g., `(a+)+`). These lead to exponential complexity. Always test your patterns against large, non-matching strings to ensure they fail quickly.

Which flavor of Regex is used here?

We use the standard JavaScript Regex engine (compliant with ECMAScript). Most of our patterns are compatible with PCRE (PHP, Python) and .NET with minor adjustments.