Regex Tester
A simple and modern tool to test your regular expressions in real-time.
About Our Online Regex Tester
Regular expressions (or "regex") can be tricky to get right. We built this tool to make it easier for you to write, test, and debug your regex patterns. It all happens in real-time, right in your browser. As you type your pattern, you'll instantly see all the matches highlighted in the test string below. It's a great way to learn regex or to perfect a complex pattern for your code.
How to Use This Tool
Using our regex tester is simple. We wanted a tool that was powerful but not complicated.
- Enter your pattern: Type your regular expression in the "Regular Expression" input field at the top. You don't need to add the slashes (
/
) at the beginning or end. - Load a sample (optional): Use the "Load a Sample" dropdown to instantly load a common pattern and test string.
- Add your text: In the "Test String" box, paste or type the text you want to run your expression against.
- Select flags: To the right of the expression field, you can select flags like
g
(global, find all matches),i
(case-insensitive), andm
(multiline). - Check the results: As you type, the tool will update automatically. Any text that matches your pattern will be highlighted. Below the text area, the "Match Information" box will give you a detailed list of every match and any capture groups within them.
Your privacy is important to us. All the testing happens on your computer. We don't send your regex patterns or test strings to our servers.
Regex Cheatsheet
Here's a quick reference for some of the most common regex tokens.
Character | Description |
---|---|
. | Matches any single character except a newline. |
\d | Matches any digit (0-9). |
\w | Matches any word character (letters, numbers, and underscore). |
\s | Matches any whitespace character (space, tab, newline). |
[abc] | Character set. Matches any character in the brackets (a, b, or c). |
^ | Asserts the start of the string (or the start of a line in multiline mode). |
$ | Asserts the end of the string (or the end of a line in multiline mode). |
* , + , ? | Quantifiers. Match the preceding token 0 or more, 1 or more, or 0 or 1 time. |
( ... ) | Capturing group. Groups tokens together and creates a capture group for extracting a substring. |
\| | Acts like a boolean OR. Matches the expression before or after the pipe. |
Frequently Asked Questions
How do I match an email address with regex?
A great pattern for matching most common email addresses is \b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b
. This pattern looks for a sequence of allowed characters, followed by an @ symbol, then a domain name. We recommend using this with the `g` (global) flag to find all emails in your text.
What is a good regex for finding URLs?
To find URLs that start with http or https, you can use this pattern: https?://[^\s/$.?#].[^\s]*
. It looks for "http" followed by an optional "s", and then matches all characters that aren't spaces.
How do I match an IPv4 address?
You can match an IPv4 address with \b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b
. This pattern looks for four groups of 1-to-3-digit numbers separated by dots. It's a simple way to find IP addresses in a block of text.
How can I match a date in YYYY-MM-DD format?
To match a date formatted like YYYY-MM-DD, you can use \d{4}-\d{2}-\d{2}
. This simply looks for four digits, a hyphen, two digits, a hyphen, and two more digits.
What is a regex to match a US phone number?
US phone numbers come in many formats. A flexible regex to catch most of them is \(?\d{3}\)?[-\.\s]?\d{3}[-\.\s]?\d{4}
. This pattern handles formats like (123) 456-7890, 123-456-7890, and 123.456.7890.
How do I match an HTML tag and its closing tag?
You can match a simple HTML tag pair with <([a-z][a-z0-9]*)\b[^>]*>.*?<\/\1>
. This uses a backreference (\1
) to ensure the closing tag matches the opening one (e.g., <strong>
matches </strong>
).
How can I match a hex color code?
A good regex for hex codes is #?([a-f0-9]{6}|[a-f0-9]{3})\b
. This pattern finds an optional # symbol followed by either six or three hexadecimal characters.
What's a regex for a simple username?
To validate a username that allows letters, numbers, and underscores between 3 and 16 characters long, use ^[a-zA-Z0-9_]{3,16}$
. The `^` and `$` anchors ensure the entire string matches the pattern.
How can I validate a strong password with regex?
A common requirement is to have a password with at least 8 characters, one uppercase letter, one lowercase letter, and one number. The regex ^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{8,}$
is perfect for this. It uses "lookaheads" (`?=...`) to check for all the conditions at once.
How do I match a credit card number?
To find a 16-digit number formatted as four blocks of four, optionally separated by spaces or hyphens, you can use \b\d{4}[ -]?\d{4}[ -]?\d{4}[ -]?\d{4}\b
.
What is a regex to match time in HH:MM format?
To match time in a 24-hour format like 09:30 or 18:00, use ([01]?[0-9]|2[0-3]):[0-5][0-9]
. This correctly handles hours from 00 to 23 and minutes from 00 to 59.
How can I find all hashtags in a text?
You can easily find hashtags with the pattern #[A-Za-z0-9_]+
. This looks for a # symbol followed by one or more letters, numbers, or underscores.
How do I match common image file names?
To find file names ending in common image extensions, use [\w-]+\.(jpg|jpeg|png|gif|svg)\b
. This looks for a word and then checks if it's followed by one of the specified extensions.
How can I extract only the text inside double quotes?
To extract content from within double quotes, use "(.*?)"
. The parentheses create a capture group for the text inside the quotes, and the `?` makes the `*` non-greedy, so it stops at the first closing quote it finds.
What's a regex for a MAC address?
You can match a MAC address with either colons or hyphens as separators by using ([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})
.
How do I match only positive integers?
To match a whole number that isn't zero or negative, use ^[1-9]\d*$
. The `^` and `$` ensure the whole string must be a positive integer.
How do I match both positive and negative integers?
To match any integer (positive, negative, or zero), you can use ^-?[1-9]\d*|0$
. This handles negative numbers and also correctly matches a single zero.
What is a regex for a decimal number?
To match a number with a decimal point, like 12.34 or -0.5, you can use ^-?\d*\.\d+$
. This pattern requires at least one digit after the decimal point.
How can I find a UUID or GUID in text?
To find a standard UUID or GUID, use the pattern [0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}
. We recommend using the `i` flag to make it case-insensitive.
Is the text I enter on this tool secure?
Yes, absolutely. This tool is built to run entirely in your web browser. Your regular expressions and test strings are never sent to our servers. Everything stays on your computer, so you can test sensitive data without any worries.