20 common regular expressions — copy, test, and use instantly
Email Address
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$Example: user@example.com
URL (http/https)
https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&/=]*)Example: https://example.com/path
Phone (US)
^(\+1)?[-.\s]?\(?[0-9]{3}\)?[-.\s]?[0-9]{3}[-.\s]?[0-9]{4}$Example: (555) 123-4567
IPv4 Address
^((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]?)$Example: 192.168.1.1
Date (YYYY-MM-DD)
^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$Example: 2024-01-15
Time (HH:MM)
^([01]?[0-9]|2[0-3]):[0-5][0-9]$Example: 14:30
Hex Color
^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$Example: #FF5733
Strong Password
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$Example: P@ssw0rd!
Credit Card
^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11})$Example: 4111111111111111
ZIP Code (US)
^\d{5}(-\d{4})?$Example: 12345 or 12345-6789
Username (alphanumeric)
^[a-zA-Z0-9_]{3,20}$Example: user_name123
Slug (URL-friendly)
^[a-z0-9]+(?:-[a-z0-9]+)*$Example: my-blog-post
HTML Tag
<([a-z][a-z0-9]*)\b[^>]*>(.*?)<\/\1>Example: <div class='test'>content</div>
JWT Token
^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$Example: eyJ...header.payload.signature
Semantic Version
^(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-]*))*))?$Example: 1.2.3 or 2.0.0-beta.1
MAC Address
^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$Example: 00:1A:2B:3C:4D:5E
Positive Integer
^[1-9]\d*$Example: 42
Decimal Number
^-?\d+(\.\d+)?$Example: -3.14
YouTube URL
^(https?:\/\/)?(www\.)?(youtube\.com\/watch\?v=|youtu\.be\/)([\w-]{11})Example: https://youtube.com/watch?v=dQw4w9WgXcQ
Base64 String
^[A-Za-z0-9+/]*={0,2}$Example: SGVsbG8gV29ybGQ=
Browse 20 common regular expressions online free. Copy patterns for email, URL, phone, password, IP address, date, hex color, credit card, JWT, and more. Test each pattern against your own input with instant match/no-match feedback. Filter by category (Validation, Security, Network, etc.) or search by name. All patterns are battle-tested and production-ready.
Writing regex from scratch is time-consuming and error-prone. A single misplaced character can cause security vulnerabilities (like allowing invalid emails) or false positives (rejecting valid input). This collection provides battle-tested patterns for the most common validation needs. Each pattern has been verified against real-world inputs. Using proven patterns saves development time and prevents bugs in form validation, data parsing, and input sanitization.
JavaScript: new RegExp(pattern).test(input) or /pattern/.test(input). Python: import re; re.match(pattern, input). PHP: preg_match('/pattern/', input). Java: Pattern.compile(pattern).matcher(input).matches(). C#: Regex.IsMatch(input, pattern). Most patterns in this collection use standard regex syntax compatible with all these languages. Some patterns may need minor adjustments for language-specific syntax.
Yes, these are commonly used patterns. However, always test with your specific use case as requirements may vary.
Use new RegExp(pattern).test(input) or /pattern/.test(input). For example: /^[a-z]+$/.test('hello') returns true.
^ means 'start of string' and $ means 'end of string'. Together they ensure the entire string matches the pattern, not just a part of it.
Add the 'i' flag: new RegExp(pattern, 'i') or /pattern/i. This makes the pattern match both uppercase and lowercase letters.
Yes, use the test input field below each pattern to test it against your own input. A green 'Match' or red 'No match' indicator shows the result.
Chúng tôi không chỉ thiết kế website, mà còn giúp doanh nghiệp xây dựng thương hiệu số mạnh mẽ. Cung cấp dịch vụ thiết kế website trọn gói từ thiết kế đến tối ưu SEO. Hãy liên hệ ngay với Tấn Phát Digital để cùng tạo nên những giải pháp công nghệ đột phá, hiệu quả và bền vững cho doanh nghiệp của bạn tại Hồ Chí Minh.
Tạo file .env và .env.example cho dự án.
Tạo .gitignore cho Node.js, Python, Java.
Tạo mock JSON data cho API testing.
Format và phân tích API response.
Test REST API: GET, POST, PUT, DELETE.
Chuyển đổi Binary, Hex, Base32.
Mã hóa/giải mã Base64.
Chuyển đổi Decimal, Binary, Hex.
Tạo CSS box-shadow trực quan.
Tính quyền file Linux.
Kiểm tra WCAG accessibility.
Tạo bảng màu ngẫu nhiên.