Regex Tester Developer Tool
Test a regular expression against sample text with live match highlighting.
Getting a regular expression exactly right usually means several rounds of trial and error against real sample text, since a pattern that looks correct can still match too much, too little, or nothing at all. This free regex tester is a developer tool that highlights every match live as you type, using JavaScript's regex engine, entirely in your browser.
Pattern
g global · i case-insensitive · m multiline · s dotAll · u unicode
Test string
Matches 0
Match details
- No matches yet.
Runs entirely in your browser — no data is sent anywhere.
Anchors and quantifiers, briefly
^ and $ anchor a match to the start and end of the string (or of each line, with the m flag). *, +, and ? mean "zero or more," "one or more," and "zero or one" of whatever precedes them, and {n,m} gives an explicit repetition range. \d, \w, and \s match a digit, a word character, and whitespace respectively, with the uppercase versions (\D, \W, \S) negating each. A character class in brackets ([a-z0-9_-]) matches any one of the characters listed, and [^...] negates the whole class.
Greedy vs lazy matching
By default, quantifiers are greedy: <.+> against <b>bold</b> matches the entire string from the first < to the last >, not just <b>, because .+ grabs as much as it can before backtracking only as far as necessary to let the rest of the pattern succeed. Appending ? to a quantifier (.+?) makes it lazy instead, matching as little as possible — <.+?> against the same string stops at the first >, giving just <b>. This one distinction accounts for a large share of "why did my regex match too much" surprises, especially with HTML-like or nested-delimiter text.
Groups and captures
Parentheses (...) create a capturing group — both a way to apply a quantifier to a whole sub-pattern and a way to extract just that portion of the match afterward (shown per-match below when the pattern includes any). (?:...) is a non-capturing group, useful when you need the grouping behaviour without cluttering the results with a capture you don't need. Named groups ((?<year>\d{4})) let you reference a capture by name instead of by position, which keeps a pattern with several groups readable.
JavaScript regex vs PHP (PCRE)
This tool tests against JavaScript's built-in regex engine, since that's what runs in your browser — but a Laravel app's regex: validation rule is evaluated server-side by PHP's PCRE engine instead. The two are close enough that most everyday patterns behave identically, but PCRE supports some features JavaScript doesn't natively (lookbehind support varies by JS engine version, atomic groups, possessive quantifiers), and delimiter syntax differs — PHP wraps a pattern in delimiters like /pattern/ or #pattern# plus flags, rather than JavaScript's /pattern/flags literal. For a pattern destined for a Laravel regex: rule, treat a match here as a strong signal, not an absolute guarantee, and spot-check anything using an advanced feature directly in PHP.