Regex Tester Guide — How to Write and Test Regular Expressions

Updated October 2026 · 5 min read

Quick start: Open the free Regex Tester — type a pattern and test string to see matches highlighted in real time.

A regular expression (regex) is a sequence of characters defining a search pattern. They are used everywhere: form validation, log parsing, find-and-replace in code, URL routing and data extraction. The syntax looks intimidating but a small set of rules covers 90% of real-world use cases.

Core Regex Syntax

PatternMeaningExample
.Any character except newlinec.t → cat, cut, c3t
*0 or more of precedingab* → a, ab, abb
+1 or more of precedingab+ → ab, abb (not a)
?0 or 1 of preceding (optional)colou?r → color, colour
^Start of string^Hello → starts with Hello
$End of stringend$ → ends with "end"
[abc]Character class[aeiou] → any vowel
\dAny digit (0–9)\d{4} → 4-digit number
\wWord character (a-z, A-Z, 0-9, _)\w+ → any word
{n,m}Between n and m repetitions\d{3,5} → 3 to 5 digits

Practical Patterns You Can Use Today

Email address:

^[\w.-]+@[\w.-]+\.[a-zA-Z]{2,}$

US phone (flexible):

^\+?1?\s?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}$

URL (http/https):

https?:\/\/[\w-]+(\.[\w-]+)+([\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-])?

HEX colour code:

^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$

Flags — Global, Case-Insensitive, Multiline

Regex flags modify matching behaviour. The three most important: g (global — find all matches, not just first), i (case-insensitive), m (multiline — ^ and $ match line starts/ends, not just the whole string). Most regex testers let you toggle flags — test your pattern with and without g to see the difference.

Test Regular Expressions Online

Live match highlighting, group captures and flag toggles. No account needed.

Open Free Regex Tester →