Regex Tester

Test and debug regular expressions in real-time.

100% client-side. Your data never leaves your browser.

/ / g
0 matches
Matches will be highlighted here...

Quick Reference

Character Classes
. - Any character
\d - Digit [0-9]
\w - Word char [a-zA-Z0-9_]
\s - Whitespace
Quantifiers
* - 0 or more
+ - 1 or more
? - 0 or 1
{n,m} - n to m times
Anchors
^ - Start of string/line
$ - End of string/line
\b - Word boundary
\B - Non-word boundary
Groups
(abc) - Capture group
(?:abc) - Non-capture
a|b - Alternation
[abc] - Character set

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

100%

Client-Side

All processing happens in your browser. Your data never touches our servers.

Free

No Signup

Use unlimited times without creating an account.

Fast

Real-Time

Matches update instantly as you type. See results in real-time.

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.

Contact

Frequently 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 g flag. Use preg_match_all() or Str::matchAll() to get every match.
  • Add the u flag 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}$/'].