This tool runs entirely in your browser. No data is sent to any server.

Regex Tester Online — Test Regular Expressions Live, Free

Works offline No server calls No account GDPR-safe
/ /
Quick Reference
. Any character except newline
\d Digit [0-9]
\D Non-digit
\w Word character [a-zA-Z0-9_]
\W Non-word character
\s Whitespace
\S Non-whitespace
* Zero or more (greedy)
+ One or more (greedy)
? Zero or one
{n,m} Between n and m
^ Start of string / line
$ End of string / line
[abc] Character class
[^abc] Negated character class
(abc) Capturing group
(?:abc) Non-capturing group
a|b Alternation (a or b)
\b Word boundary
(?=abc) Positive lookahead
(?!abc) Negative lookahead

What Is a Regular Expression?

A regular expression (regex) is a pattern-matching language built into virtually every programming language and text editor. It lets you describe a string pattern — like "four digits followed by a hyphen" or "any email address" — and find, validate, or replace text that matches it.

Common Use Cases

  • Validation — Email addresses, phone numbers, postcodes, IP addresses, and passwords all have patterns that regex can enforce.
  • Search and replace — Find all occurrences of a pattern in a file and replace them — in code editors, CLI tools (sed), and PHP's preg_replace().
  • Parsing — Extracting structured data from log files, HTML, CSV, or API responses that don't have a dedicated parser.
  • Routing — Laravel route constraints use regex: ->where('id', '[0-9]+').

Tips for Beginners

Start with the g (global) flag to find all matches, not just the first. Use i for case-insensitive matching. Anchor with ^ and $ when you need to match the entire string, not just a substring. Prefer non-capturing groups (?:...) when you don't need to reference the captured value — they're faster and keep match indexes clean.

Regex in PHP

PHP uses the PCRE (Perl Compatible Regular Expressions) engine. Unlike JavaScript, PHP regex patterns require delimiters — e.g. /pattern/flags.

  • preg_match('/pattern/', $str) — Returns 1 if the pattern matches, 0 if not
  • preg_match_all('/pattern/', $str, $matches) — Finds all matches and populates $matches
  • preg_replace('/pattern/', $replacement, $str) — Replaces all matches with a replacement string
  • preg_split('/pattern/', $str) — Splits a string by a regex pattern
  • preg_quote($str) — Escapes special regex characters in a user-supplied string

In Laravel, validation rules support regex: 'field' => ['regex:/^[a-z]+$/i']. Route parameter constraints also use regex: ->where('id', '[0-9]+').

Privacy & How It Works

All pattern matching runs in your browser using JavaScript's native RegExp engine. No pattern or test string is transmitted to any server.

  • No server calls — Regex evaluation runs locally in your browser.
  • Works offline — Once the page loads, no internet is needed.
  • GDPR-safe — Zero data collection or transmission.
Built by TuringComplete
Check out our open-source developer tools.
Explore Tools