Biblioteca de Regex
Navegue uma coleção curada de padrões regex para email, UUID, IP e URL
Curated Regular Expression Patterns for Common Validation
Writing correct regular expressions from scratch is time-consuming and error-prone — email validation alone has dozens of edge cases around quoted local parts, internationalized domain names, and RFC 5322 compliance that most ad-hoc patterns miss. The Regex Library provides a browsable collection of production-tested patterns organized by category, each with clear documentation of what it matches, what it intentionally excludes, and example strings for both positive and negative cases.
Every pattern in the library has been validated against real-world edge cases and includes a one-click copy feature. Patterns cover common validation needs including email addresses, URLs, UUIDs, IP addresses (v4 and v6), phone numbers, dates, hex colors, credit card formats, slugs, and semantic versions. Each entry explains the regex fragment by fragment so you understand what you are copying rather than using it as a black box.
Identity and Communication Patterns
Patterns for validating user identity and communication fields:
- Email (RFC 5322 simplified): Validates standard email formats with domain validation, rejecting obvious invalid inputs while allowing legitimate edge cases like plus-addressing
- Phone (E.164 international): Matches international phone numbers with country code prefix
- URL (HTTP/HTTPS): Validates web URLs with optional query strings and fragments
- Domain name: Validates hostnames including subdomains and TLDs
- Slug: Validates URL-safe slugs (lowercase letters, numbers, hyphens)
Each pattern includes notes on intentional limitations — for example, the email pattern does not validate that the domain's MX record exists, only that the format is structurally valid.
Identifier and Format Patterns
Patterns for validating technical identifiers and data formats:
- UUID v4: Matches the canonical 8-4-4-4-12 format with correct version digit
- IPv4 address: Validates dotted-quad notation with octet range checking (0-255)
- IPv6 address: Handles full notation, compressed (::) notation, and mixed IPv4/IPv6
- MAC address: Matches colon-separated and dash-separated hardware addresses
- Hex color: Validates 3-digit and 6-digit CSS hex color codes with optional # prefix
- Semantic version: Matches semver with optional pre-release and build metadata
- JWT token: Validates the three-part base64url structure of JSON Web Tokens
Using Patterns Safely
Best practices when using regex patterns from a library:
- Understand before copying: Read the fragment explanation to know what edge cases are and are not covered
- Test with your data: Every application has unique input patterns — test the regex against your actual user input samples
- Add anchors: Use
^and$to prevent partial matches when validating complete strings - Consider performance: Some patterns with alternation or backtracking behave poorly on very long inputs — test with maximum expected input length
- Complement with logic: Regex validates format, not semantics — an email that matches the pattern may still not exist, an IP that matches may not be routable
The library clearly marks which patterns are suitable for strict validation (rejecting invalid input) versus lenient extraction (finding patterns within larger text).
Code Examples
Common Validation Patterns
// Email (simplified RFC 5322)
const emailRegex = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
// UUID v4
const uuidV4Regex = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
// IPv4 with range validation
const ipv4Regex = /^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/;
// Semantic Version (semver)
const semverRegex = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
// CSS Hex Color (3 or 6 digits)
const hexColorRegex = /^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/; Perguntas Frequentes
What is the Regex Library?
The Regex Library is a curated collection of common regular expression patterns used in software development. It includes patterns for email addresses, UUIDs, IPv4 and IPv6 addresses, URLs, domains, slugs, hex color codes, MAC addresses, and JWT tokens. Each pattern comes with an explanation, valid and invalid examples, and copy functionality.
How do I use a pattern from the library?
Browse or search the collection to find the pattern you need. Each entry shows the regex pattern string, a description of what it matches, a detailed explanation of how it works, and examples of valid and invalid inputs. Click the copy button to copy the pattern to your clipboard for use in your code.
Are these patterns suitable for production use?
These patterns cover the most common formats and are good starting points for validation. However, some formats (like email) have edge cases defined in RFCs that a single regex cannot fully cover. For critical production validation, consider combining regex with additional logic or using dedicated validation libraries.
What is the difference between the Regex Library and the Regex Explainer?
The Regex Library provides a pre-built collection of common patterns you can browse and copy. The Regex Explainer takes any regex you provide and breaks it down into fragments, explaining each part. Use the Library to find patterns, and the Explainer to understand patterns you encounter.
Can I test a pattern against my own input?
Yes. Each pattern in the library includes valid and invalid examples so you can see what it matches. To test against your own text, you can use the Regex Tester tool and paste the pattern from the library along with your test string.
Why does the IPv6 pattern only match full-form addresses?
The IPv6 pattern matches the fully expanded form (eight groups of four hex digits). Shortened forms using :: (double colon) require more complex regex or a multi-step parser. The full-form pattern is simpler and avoids ambiguity in matching.
Is my data sent to a server?
No. The Regex Library is a static collection rendered in your browser. No data is sent to any server. If you use the test functionality, all matching is performed locally using JavaScript's built-in RegExp engine.
What categories are available?
Patterns are organized into four categories: Identifiers (UUID, JWT), Network (IPv4, IPv6, MAC address), Web (email, URL, domain, slug), and Formatting (hex color). You can filter by category or search by name and description.