RegexRef Logo

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.
Match Details0.05ms
#12024-06-27 [INFO] System booted successfully.\n2024-06-27 [WARN] Memory usage at 85%.\n2024-06-28 [ERROR] Connection timed out.index: 0, length: 127
date2024-06-27
levelINFO
msgSystem booted successfully.\n2024-06-27 [WARN] Memory usage at 85%.\n2024-06-28 [ERROR] Connection timed out.
RegexRef Pro

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.

$9/mo

Billed annually or $12/mo

Upgrade to Pro

7-day money-back guarantee.

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,}$/
Matches
user@example.comjohn.doe+test@sub.domain.org
Non-matches
user@.com@missing-user.comuser@example
javascript
const regex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
regex.test('user@example.com');
📖 View Guide
🔗

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()@:%_\+.~#?&\/=]*)$/
Matches
https://www.example.comhttp://sub.example.co.uk/path?q=1
Non-matches
www.example.comhttps://htp://example.com
javascript
const 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');
📖 View Guide
🔑

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,}$/
Matches
StrongP@ss1P4ssw0rd!
Non-matches
weakpassOnlyUpper1NoSpecialChar1
javascript
const regex = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/;
regex.test('StrongP@ss1');
📖 View Guide
🖥️

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]?)$/
Matches
192.168.1.1255.255.255.0
Non-matches
256.1.1.1192.168.1192.168.1.1.1
javascript
const 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');
📖 View Guide
🎨

Hex Color Code

Matches 3 or 6 digit hex color codes.

/^#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/
Matches
#FFF#000000#a3f
Non-matches
#ZZZ#1234123456
javascript
const regex = /^#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/;
regex.test('#FFFFFF');
📖 View Guide
📅

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])$/
Matches
2023-12-251999-01-01
Non-matches
2023-13-0123-01-012023/12/25
javascript
const regex = /^\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])$/;
regex.test('2023-12-25');
📖 View Guide
🏷️

Extract HTML Tags

Matches HTML tags and their attributes.

/<\/?([a-zA-Z0-9]+)(?:\s+[^>]+)?>/g
Matches
<div class="test"></div><img>
Non-matches
1 < 2Not a tag
javascript
const regex = /<\/?([a-zA-Z0-9]+)(?:\s+[^>]+)?>/g;
const str = '<div>test</div>';
const tags = str.match(regex);
📖 View Guide
✂️

Trim Whitespace

Matches leading and trailing whitespace to trim it.

/^\s+|\s+$/g
Matches
test \twordend\n
Non-matches
no-whitespacemiddle whitespace
javascript
const regex = /^\s+|\s+$/g;
'  test  '.replace(regex, '');
📖 View Guide

Comprehensive Regex Cheat Sheet

A quick reference guide to regular expression syntax, character classes, anchors, quantifiers, and lookarounds.

Anchors

^
Start of Line

Matches the beginning of the string, or the beginning of a line when the multiline flag (m) is enabled.

Example:/^hello/gm
hello world
Inside a character class [^...], the caret negates the set instead.
$
End of Line

Matches the end of the string, or the end of a line when the multiline flag (m) is enabled.

Example:/world$/gm
hello world
\b
Word Boundary

Matches a position between a word character (\w) and a non-word character (\W), or at the start/end of the string.

Example:/\bcat\b/g
cat concatenate
Useful for matching whole words only. Zero-width assertion — matches a position, not a character.
\B
Non-Word Boundary

Matches a position that is NOT a word boundary — i.e. between two word characters or two non-word characters.

Example:/\Bcat\B/g
cat concatenate
The opposite of \b. Matches "cat" inside "concatenate" but not the standalone word "cat".

Character Classes

.
Any Character

Matches any single character except newline (\n). With the s (dotAll) flag, it also matches newlines.

Example:/c.t/g
cat cot cut
\d
Digit

Matches any digit character (0-9). Equivalent to [0-9].

Example:/\d+/g
abc 123 def
\D
Non-Digit

Matches any character that is NOT a digit. Equivalent to [^0-9].

Example:/\D+/g
abc 123 def
\w
Word Character

Matches any word character: letters, digits, and underscore. Equivalent to [a-zA-Z0-9_].

Example:/\w+/g
hello world!
\W
Non-Word Character

Matches any character that is NOT a word character. Equivalent to [^a-zA-Z0-9_].

Example:/\W+/g
hello world!
\s
Whitespace

Matches any whitespace character: space, tab, newline, carriage return, form feed, and vertical tab.

Example:/\s/g
hello world
\S
Non-Whitespace

Matches any character that is NOT a whitespace character.

Example:/\S+/g
hello world
[abc]
Character Set

Matches any one of the characters inside the brackets. Characters are treated literally (except ], \, ^, -).

Example:/[cb]at/g
cat bat rat
[^abc]
Negated Character Set

Matches any single character that is NOT listed inside the brackets.

Example:/[^cb]at/g
cat bat rat
[a-z]
Character Range

Matches any character in the specified range. Multiple ranges can be combined, e.g. [a-zA-Z].

Example:/[a-z]+/g
Hello World 123
[0-9]
Digit Range

Matches any digit in the specified range. Equivalent to \d when using [0-9].

Example:/[0-9]+/g
abc 123 def 456

Quantifiers

*
Zero or More

Matches the preceding element zero or more times. Greedy by default — matches as many as possible.

Example:/ab*c/g
ac abc abbc
+
One or More

Matches the preceding element one or more times. Greedy by default.

Example:/ab+c/g
ac abc abbc
?
Zero or One

Matches the preceding element zero or one time. Makes the element optional.

Example:/colou?r/g
color colour
{n}
Exactly N

Matches the preceding element exactly n times.

Example:/a{3}b/g
aab aaab aaaab
{n,}
N or More

Matches the preceding element n or more times. Greedy by default.

Example:/a{2,}b/g
aab aaab aaaab
{n,m}
Between N and M

Matches the preceding element at least n and at most m times. Greedy by default.

Example:/a{2,3}b/g
ab aab aaab aaaab
*?
Lazy Zero or More

Matches the preceding element zero or more times, but as few times as possible (lazy/non-greedy).

Example:/<.*?>/g
<b>bold</b>
Without the ?, the greedy version <.*> would match the entire string as one match.
+?
Lazy One or More

Matches the preceding element one or more times, but as few times as possible (lazy/non-greedy).

Example:/<.+?>/g
<b>bold</b>
??
Lazy Zero or One

Matches the preceding element zero or one time, preferring zero (lazy/non-greedy).

Example:/colou??r/g
color colour
Prefers matching without the optional element when possible.

Groups & Lookarounds

(...)
Capturing Group

Groups part of the pattern and captures the matched substring for later use via backreferences or match results.

Example:/(\d{4})-(\d{2})-(\d{2})/
2024-01-15
Captured groups are numbered left-to-right starting at 1. Group 0 is always the entire match.
(?:...)
Non-Capturing Group

Groups part of the pattern without capturing the matched text. Useful for applying quantifiers to a group without saving the match.

Example:/(?:http|https):///g
http://example.com https://example.com
More efficient than capturing groups when you don't need the matched content.
(?<name>...)
Named Capturing Group

Creates a capturing group with a name, making matches accessible by name instead of just by number.

Example:/(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/
2024-01-15
Python uses (?P<name>...) syntax. Go also uses (?P<name>...). JavaScript and Rust use (?<name>...).
\1
Backreference

Matches the same text that was previously matched by the specified capturing group number.

Example:/(\w+) \1/g
hello hello world
Not supported in Go (RE2 engine). Use \k<name> for named backreferences in JavaScript.

Frequently 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.