Regex Tester

Test and debug regular expressions with live matching and explanations.

//

Flags:

  • g - Global (find all matches)
  • i - Case insensitive
  • m - Multiline (^ and $ match line breaks)

Regular Expression Quick Reference

1. Write your pattern

Enter your regex in the pattern field. Use the reference tables below if you need help with metacharacters, quantifiers, or flags. The pattern updates matching in real time.

2. Paste test text

Paste the string you want to match against. All matches are highlighted instantly. Use the global flag (g) to find all matches, or remove it to match only the first occurrence.

3. Debug and refine

Adjust your pattern until you get the matches you need. Check capture groups to extract specific parts. Copy the final pattern into your code.

Regex Metacharacters

CharacterMeaningExampleMatches
.Any character except newlinec.t"cat", "cut", "c3t"
^Start of string^Hello"Hello world" (at start)
$End of stringworld$"Hello world" (at end)
*Zero or moreab*c"ac", "abc", "abbc"
+One or moreab+c"abc", "abbc" (not "ac")
?Zero or one (optional)colou?r"color" and "colour"
{n}Exactly n times\d{4}Exactly 4 digits
{n,m}Between n and m times\d{2,4}2 to 4 digits
[abc]Any one of a, b, c[aeiou]Any vowel
[^abc]Not a, b, or c[^0-9]Any non-digit
(abc)Capture group(\d+)Captures one or more digits
a|ba or bcat|dog"cat" or "dog"
\dAny digit [0-9]\d+One or more digits
\wWord char [a-zA-Z0-9_]\w+One or more word chars
\sWhitespace\s+One or more spaces/tabs
\bWord boundary\bword\bWhole word "word" only

Common Regex Patterns

Email address/^[\w.-]+@[\w.-]+\.[a-z]{2,}$/i
US phone number/^\+?1?[-.\s]?\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}$/
URL (http/https)/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z]{2,6}/
IPv4 address/^(\d{1,3}\.){3}\d{1,3}$/
Hex color code/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/
Date (YYYY-MM-DD)/^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/
Strong password/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/
Digits only/^\d+$/

Regex Flags

g — Global

Find all matches in the string, not just the first. Without g, only the first match is returned.

i — Case-insensitive

Makes the match ignore upper/lower case. /hello/i matches "Hello", "HELLO", and "hello".

m — Multiline

Makes ^ and $ match the start/end of each line, not just the whole string.

s — dotAll

Makes . match any character including newlines. Without s, . does not match \n.

Frequently Asked Questions

Common questions about Regex Tester