Regex Tester

Test and debug your regular expressions with real-time pattern matching and detailed results.

How to Use the Regex Tester?

Enter your regular expression pattern and test string to see matches, groups, and positions.

Enter your regex pattern without delimiters (/ /)

What Are Regular Expressions?

Regular expressions (regex or regexp) are sequences of characters that define search patterns. They originated in formal language theory in the 1950s and were first implemented in Unix tools like grep, sed, and awk in the 1970s. Today, regex is supported in virtually every programming language — JavaScript, Python, Java, PHP, C#, Go, Ruby, and more — making it one of the most universally useful skills a developer can learn.

At their core, regular expressions let you describe a pattern rather than a literal string. Instead of searching for the exact word "cat", you can search for "any three-letter word starting with c" using the pattern c\w{2}. This power makes regex essential for data validation, text parsing, search-and-replace operations, log analysis, and input sanitisation.

Regex Syntax Cheat Sheet

Character Classes

PatternMeaningExample Match
.Any character except newlinea, Z, 5, @
\dAny digit (0–9)0, 7, 3
\DAny non-digita, !, space
\wWord character (a-z, A-Z, 0-9, _)a, Z, 5, _
\WNon-word character!, @, space
\sWhitespace (space, tab, newline)space, \t, \n
[abc]Any character in the seta, b, or c
[^abc]Any character NOT in the setd, 1, !
[a-z]Any character in rangea through z

Quantifiers

PatternMeaningExample
*0 or moreab*c matches ac, abc, abbc
+1 or moreab+c matches abc, abbc (not ac)
?0 or 1 (optional)colou?r matches color, colour
{n}Exactly n times\d{4} matches 2024, 1999
{n,m}Between n and m times\d{2,4} matches 12, 123, 1234
*?, +?Lazy (non-greedy) versionsMatch as few characters as possible

Anchors and Groups

PatternMeaning
^Start of string (or line with m flag)
$End of string (or line with m flag)
\bWord boundary
(abc)Capturing group — matches "abc" and remembers it
(?:abc)Non-capturing group — groups without capturing
a|bAlternation — matches "a" or "b"
(?=abc)Positive lookahead — matches if followed by "abc"
(?<=abc)Positive lookbehind — matches if preceded by "abc"

Common Regex Patterns

Greedy vs Lazy Matching

By default, quantifiers (*, +, {n,m}) are greedy — they match as many characters as possible. Adding ? after a quantifier makes it lazy (non-greedy), matching as few characters as possible.

This distinction matters when parsing structured text. Given the input <b>bold</b> and <i>italic</i>, the greedy pattern <.*> matches the entire string from the first < to the last >. The lazy pattern <.*?> matches only <b>, then </b>, then <i>, then </i> — each tag individually.

Regex Flags Explained

Common Mistakes and How to Avoid Them

Frequently Asked Questions — Regex Tester

Written and reviewed by the FreeBytes Editorial Team · Last updated: June 2026