Regex Tester
Test and debug Regular Expressions in real-time
[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}Regex Guide — Learn by Example
Regular Expressions (Regex) are patterns used to match text. Click "Try it" on any example to load it into the tester above.
1Literal Characters — Match Exact Text
The simplest regex matches exact text. Just type the word or phrase you want to find.
/hello/giMatches the word "hello" regardless of case (i flag). The g flag finds all occurrences, not just the first.
/ice cream/gSpaces are literal in regex — this matches the exact phrase "ice cream" with the space.
2Character Classes — Match Types of Characters
Use shorthand codes to match categories: \d for digits, \w for word characters, \s for spaces, and . for any character.
/\d+/g\d matches any digit [0-9]. The + means "one or more". So \d+ matches sequences of digits like 1234, 2024, 03, 15, 99, 50, 3.
/\w+/g\w matches letters, digits, and underscore [a-zA-Z0-9_]. Notice @#$% are NOT matched because they aren't word characters.
/c.t/gThe dot matches ANY single character. So c.t matches cat, cot, cut, c@t, c3t — but not "c t" (space counts!) and not "cart" (too many chars between c and t).
/\s+/g\s matches spaces, tabs (\t), newlines (\n), and other whitespace. \s+ matches one or more whitespace characters in a row.
3Character Sets [...] — Custom Groups
Square brackets let you define custom sets of characters to match. Use [abc] for specific chars, [a-z] for ranges, and [^abc] to negate.
/[aeiou]/giMatches any single character that is a, e, i, o, or u. Each vowel is matched individually.
/#[0-9a-fA-F]{3,6}/gThe range [0-9a-fA-F] matches any hex digit. {3,6} means the hex part must be 3 to 6 characters long.
/[^a-zA-Z\s]/gThe ^ inside brackets means NOT. This matches anything that is NOT a letter and NOT whitespace — so it finds digits, punctuation, symbols.
4Quantifiers — How Many Times
Control how many times a pattern repeats: * (0+), + (1+), ? (0 or 1), {n} (exact), {n,m} (range).
/go*d/go* means zero or more o's. So it matches: gd (0 o's), god (1 o), good (2 o's), goood (3 o's), etc.
/go+d/go+ means one or more o's. Unlike *, it requires at least one o. So "gd" does NOT match, but god, good, goood all do.
/colou?r/giu? means the u is optional (0 or 1 times). Matches both "color" (American) and "colour" (British) but not "colouur".
/\d{2,4}/g{2,4} means between 2 and 4 times. \d{2,4} matches 2 to 4 digit sequences. "1" alone doesn't match (too short). "12345" partially matches as "1234".
5Anchors — Position Matching
Anchors don't match characters — they match positions. ^ matches start, $ matches end, \b matches word boundaries.
/^Error.*$/gm^ means start of line (with m flag). $ means end of line. Combined, this matches entire lines that START with "Error". The m flag makes ^ and $ work per-line instead of whole-string.
/\bcat\b/gi\b marks a word boundary (between a word char and a non-word char). \bcat\b matches "cat" as a whole word — NOT "cat" inside "concatenate" or "category".
6Groups & Capture — Extract Parts
Parentheses () create groups that capture matched text. Use them to extract specific parts from a match.
/(\d{4})-(\d{2})-(\d{2})/gEach set of parentheses captures a group. Group 1 = year (\d{4}), Group 2 = month (\d{2}), Group 3 = day (\d{2}). Click a match to see groups.
/(?<protocol>https?)://(?<domain>[\w.-]+)/g(?<name>...) creates a named group. Instead of Group 1/2, you get meaningful names like "protocol" and "domain" — much easier to read.
/(?:Mr|Mrs|Ms)\.?\s(\w+)/g(?:...) groups without capturing. The title alternatives (Mr|Mrs|Ms) are grouped but not captured. Only the name (\w+) is captured as Group 1.
7Alternation — OR Logic
The pipe | means OR — match this pattern OR that pattern.
/cat|dog|bird/giMatches "cat" OR "dog" OR "bird" anywhere in the text. Simple and powerful for matching alternatives.
/(Mon|Tues|Wednes|Thurs|Fri|Satur|Sun)day/gGroups + alternation to match all valid day names. The prefix is captured as Group 1. "Funday" doesn't match because "Fun" isn't in the alternatives.
8Lookahead & Lookbehind — Context Matching
Match a position where specific text appears before or after, without including that text in the match.
/\w+(?=@)/g(?=@) means "followed by @" but @ is NOT included in the match. So it captures just the username part before the @.
/\d+(?!\$|%)/g(?!\$|%) means "NOT followed by $ or %". Matches numbers that are NOT dollar amounts or percentages. 300, 400, and 500 match.
/(?<=\$)\d+\.?\d*/g(?<=\$) means "preceded by $" but $ is NOT in the match. Captures only the numeric amount after the dollar sign.
9Greedy vs Lazy — Controlling Match Length
By default, quantifiers are greedy (match as much as possible). Add ? to make them lazy (match as little as possible).
/<.+>/gGreedy .+ matches as MUCH as possible. It matches from the first < all the way to the LAST >, swallowing everything in between as one big match.
/<.+?>/gAdding ? makes it lazy — .+? matches as LITTLE as possible. Now each HTML tag (<b>, </b>, <i>, </i>) is matched individually.
⚡Practical Examples — Real-World Patterns
Combine everything you've learned into useful real-world patterns.
/[\w-]+\.(jpg|png|gif|svg|webp)/giMatches filenames ending with common image extensions. [\w-]+ matches the name part, \. matches the literal dot, and (jpg|png|...) matches image extensions.
/^([01]\d|2[0-3]):[0-5]\d$/gmValidates 24-hour time. Hours: 00-23 ([01]\d covers 00-19, 2[0-3] covers 20-23). Minutes: 00-59 ([0-5]\d). Invalid entries like 24:00, 12:60, and 7:30 don't match.
/\b(\w+)\s+\1\b/gi\b(\w+) captures a word, \s+ matches spaces, \1 is a back-reference that matches the SAME text as Group 1. Finds repeated words like "is is" and "the the".
/#(?:[0-9a-fA-F]{3}){1,2}\b/gMatches 3 or 6 digit hex colors. (?:[0-9a-fA-F]{3}) matches 3 hex chars, {1,2} means this group appears 1 or 2 times (for #333 or #FF5733).
About This Tool
A free online regex tester that lets you write, test, and debug regular expressions in real-time. Supports JavaScript regex syntax with all standard flags including global, case-insensitive, multiline, dotall, and unicode modes.
Features include live match highlighting, real-time pattern explanation, find-and-replace with substitution tokens, capture group inspection, common pattern presets, interactive tutorial, and a built-in cheatsheet. All processing happens locally in your browser — no data is sent to any server.