The Ultimate
Regex Tester & Cheat Sheet
Real-Time Regex Testing Sandbox
Type your regex pattern and test string below. Matches will be highlighted instantly with detailed syntax explanations.
2024-06-27 [INFO] System booted successfully.\n2024-06-27 [WARN] Memory usage at 85%.\n2024-06-28 [ERROR] Connection timed out.index: 0, length: 1272024-06-27INFOSystem booted successfully.\n2024-06-27 [WARN] Memory usage at 85%.\n2024-06-28 [ERROR] Connection timed out.Master Regular Expressions
Faster Than Ever
Upgrade your workflow with intelligent tools designed for developers who need powerful pattern matching without the headache.
AI Regex Builder
Describe what you need in plain English.
Cloud Sync Saved Patterns
Access your snippets from anywhere.
Visual Regex Tool
Debug complex patterns step-by-step.
Most Common Regex Match Patterns
Ready-to-use regular expressions for everyday development tasks like emails, URLs, and passwords. Click to copy or test them.
Email Address
Validates a standard email address format.
/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/user@example.comjohn.doe+test@sub.domain.orguser@.com@missing-user.comuser@exampleconst regex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
regex.test('user@example.com');URL Validation
Validates a web URL including http/https protocols.
/^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)$/https://www.example.comhttp://sub.example.co.uk/path?q=1www.example.comhttps://htp://example.comconst regex = /^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)$/;
regex.test('https://example.com');Strong Password
Requires at least 8 characters, one uppercase, one lowercase, one number, and one special character.
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/StrongP@ss1P4ssw0rd!weakpassOnlyUpper1NoSpecialChar1const regex = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/;
regex.test('StrongP@ss1');IPv4 Address
Matches a valid IPv4 address (0-255 blocks).
/^(?:(?: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]?)$/192.168.1.1255.255.255.0256.1.1.1192.168.1192.168.1.1.1const regex = /^(?:(?: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]?)$/;
regex.test('192.168.1.1');Hex Color Code
Matches 3 or 6 digit hex color codes.
/^#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/#FFF#000000#a3f#ZZZ#1234123456const regex = /^#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/;
regex.test('#FFFFFF');ISO Date (YYYY-MM-DD)
Matches dates in YYYY-MM-DD format (basic validation).
/^\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])$/2023-12-251999-01-012023-13-0123-01-012023/12/25const regex = /^\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])$/;
regex.test('2023-12-25');Extract HTML Tags
Matches HTML tags and their attributes.
/<\/?([a-zA-Z0-9]+)(?:\s+[^>]+)?>/g<div class="test"></div><img>1 < 2Not a tagconst regex = /<\/?([a-zA-Z0-9]+)(?:\s+[^>]+)?>/g;
const str = '<div>test</div>';
const tags = str.match(regex);Trim Whitespace
Matches leading and trailing whitespace to trim it.
/^\s+|\s+$/g test \twordend\nno-whitespacemiddle whitespaceconst regex = /^\s+|\s+$/g;
' test '.replace(regex, '');Comprehensive Regex Cheat Sheet
A quick reference guide to regular expression syntax, character classes, anchors, quantifiers, and lookarounds.
Anchors
^Matches the beginning of the string, or the beginning of a line when the multiline flag (m) is enabled.
/^hello/gm$Matches the end of the string, or the end of a line when the multiline flag (m) is enabled.
/world$/gm\bMatches a position between a word character (\w) and a non-word character (\W), or at the start/end of the string.
/\bcat\b/g\BMatches a position that is NOT a word boundary — i.e. between two word characters or two non-word characters.
/\Bcat\B/gCharacter Classes
.Matches any single character except newline (\n). With the s (dotAll) flag, it also matches newlines.
/c.t/g\dMatches any digit character (0-9). Equivalent to [0-9].
/\d+/g\DMatches any character that is NOT a digit. Equivalent to [^0-9].
/\D+/g\wMatches any word character: letters, digits, and underscore. Equivalent to [a-zA-Z0-9_].
/\w+/g\WMatches any character that is NOT a word character. Equivalent to [^a-zA-Z0-9_].
/\W+/g\sMatches any whitespace character: space, tab, newline, carriage return, form feed, and vertical tab.
/\s/g\SMatches any character that is NOT a whitespace character.
/\S+/g[abc]Matches any one of the characters inside the brackets. Characters are treated literally (except ], \, ^, -).
/[cb]at/g[^abc]Matches any single character that is NOT listed inside the brackets.
/[^cb]at/g[a-z]Matches any character in the specified range. Multiple ranges can be combined, e.g. [a-zA-Z].
/[a-z]+/g[0-9]Matches any digit in the specified range. Equivalent to \d when using [0-9].
/[0-9]+/gQuantifiers
*Matches the preceding element zero or more times. Greedy by default — matches as many as possible.
/ab*c/g+Matches the preceding element one or more times. Greedy by default.
/ab+c/g?Matches the preceding element zero or one time. Makes the element optional.
/colou?r/g{n}Matches the preceding element exactly n times.
/a{3}b/g{n,}Matches the preceding element n or more times. Greedy by default.
/a{2,}b/g{n,m}Matches the preceding element at least n and at most m times. Greedy by default.
/a{2,3}b/g*?Matches the preceding element zero or more times, but as few times as possible (lazy/non-greedy).
/<.*?>/g+?Matches the preceding element one or more times, but as few times as possible (lazy/non-greedy).
/<.+?>/g??Matches the preceding element zero or one time, preferring zero (lazy/non-greedy).
/colou??r/gGroups & Lookarounds
(...)Groups part of the pattern and captures the matched substring for later use via backreferences or match results.
/(\d{4})-(\d{2})-(\d{2})/(?:...)Groups part of the pattern without capturing the matched text. Useful for applying quantifiers to a group without saving the match.
/(?:http|https):///g(?<name>...)Creates a capturing group with a name, making matches accessible by name instead of just by number.
/(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/\1Matches the same text that was previously matched by the specified capturing group number.
/(\w+) \1/gFrequently Asked Regex Questions
Common questions about regular expressions and how to use them.
What is a regular expression (regex)?
A regular expression (regex) is a sequence of characters that specifies a search pattern. They are used by string-searching algorithms for "find" or "find and replace" operations on text, and for input validation.
How do I validate an email address with regex?
While complex email validation is usually best done by sending a verification link, a common basic regex for validating emails is: ^[^\s@]+@[^\s@]+\.[^\s@]+$
What is the difference between a positive lookahead and a negative lookahead?
A positive lookahead (?=...) asserts that a given pattern MUST follow the current position. A negative lookahead (?!...) asserts that a given pattern MUST NOT follow the current position. Neither consumes characters in the final match.
How do I test regular expressions online?
You can use the RegexRef Interactive Playground to test your regex against custom text in real-time. It provides immediate highlighting and match evaluation.