Regex Tester
Test and debug regular expressions in real-time.
100% client-side. Your data never leaves your browser.
| # | Match | Position | Groups |
|---|
Invalid Regular Expression
Quick Reference
In Laravel
Laravel uses regular expressions in three common places: validation rules, string helpers and route constraints. The first two take a full PHP pattern with delimiters, such as /^INV-\d{4}$/. Route constraints take the bare pattern, and Laravel anchors it for you.
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Str;
// Validation: use an array when the pattern contains a |
$request->validate([
'sku' => ['required', 'regex:/^(TS|MG)-\d{4}$/'],
]);
// String helpers
Str::isMatch('/^INV-\d{4}$/', 'INV-2041'); // true
Str::match('/order #(\d+)/i', 'Re: Order #1182'); // '1182'
// Route constraint: no delimiters, no ^ or $
Route::get('/invoices/{number}', ShowInvoice::class)
->where('number', 'INV-[0-9]{4}');
Str::match() returns the first capture group when the pattern has one, and the whole match when it has none.
Laravel 13.x docs: The regex rule, Str::match(), Route constraints
Client-Side
All processing happens in your browser. Your data never touches our servers.
No Signup
Use unlimited times without creating an account.
Real-Time
Matches update instantly as you type. See results in real-time.
Related Tools
Need something custom built?
I build custom Laravel tools, web apps, and SaaS platforms. If you need something beyond off-the-shelf, let's talk.
ContactFrequently Asked Questions
Will a pattern that works here also work in PHP?
Usually, yes. This tester runs your browser's JavaScript engine, and PHP uses PCRE. The everyday syntax is the same in both: character classes, quantifiers, groups, named groups and lookaheads. Three things change when you move a pattern to PHP:
- PHP needs delimiters:
/pattern/flags. If the pattern contains/, escape it or use another delimiter, such as#pattern#. - There is no
gflag. Usepreg_match_all()orStr::matchAll()to get every match. - Add the
uflag for UTF-8 text, or PHP reads a character such as é as two separate bytes.
Why does my Laravel regex rule fail when the pattern has a |?
Laravel splits a string of rules on |. In 'required|regex:/^(TS|MG)-\d{4}$/' it sees a rule called MG)-\d{4}$/ and throws a BadMethodCallException. Write the rules as an array: ['required', 'regex:/^(TS|MG)-\d{4}$/'].