# PCRE2 Regex Tester

Test PCRE2 patterns online: every named-group syntax ((?P), (?), (\\u0027n\\u0027)), possessive quantifiers, atomic groups, \\A \\z \\h shorthands, plus pcre2grep and C API snippets.

> Canonical page: https://elysiatools.com/en/tools/pcre-regex-tester

- **Category:** Development

- **Keywords:** pcre2 regex tester, pcre regex online, pcre2grep, php preg_match tester, perl compatible regular expressions, atomic group, possessive quantifier

## Overview

A regex tester for the PCRE2 flavor (PHP preg\_\*, pcre2grep, Delphi, R, and many tools). PCRE2 accepts every named-group syntax — (?P…), (?…), (?\\u0027year\\u0027…) — with backreferences \\k, \\k{year}, \\g{year} and (?P=year); the tester accepts all of them, translates to the platform\\u0027s ECMAScript engine, and reports matches, named capture groups, and a replace preview. Shorthands missing from JavaScript are expanded: \\A and \\z absolute anchors, \\Z end-before-final-newline, \\h / \\H horizontal whitespace. Possessive quantifiers and atomic groups are emulated with lookahead-capture so they really prevent backtracking, and ASCII \\d \\w \\s semantics stay PCRE2-default (toggle Unicode classes to emulate PCRE2\_UCP). Constructs the ECMAScript engine cannot express — recursion ((?R), (?1)), conditionals ((?(1)…)), callouts (?C…), \\K, \\G, backtracking verbs — are detected and rejected with an explanation. The report also builds pcre2grep command lines and a pcre2\_compile / pcre2\_match C API sketch.

## Inputs

- **Pattern** (text): (?\\d{4})-(?\\d{2})
- **Test string** (textarea): Paste the text to match against…
- **i — caseless** (checkbox)
- **m — multiline** (checkbox)
- **s — dotall** (checkbox)
- **x — extended** (checkbox)
- **U — ungreedy** (checkbox)
- **g — global scan** (checkbox)
- **Replacement template (optional)** (text): \\g / \\1
- **Unicode character classes (\d \w \s match Unicode)** (checkbox)

## When to use

- Debugging regular expressions written for PHP preg_* functions, R, Delphi, or pcre2grep command-line utilities.
- Validating patterns that use PCRE2-specific features such as atomic grouping (?>...), possessive quantifiers, or shorthand tokens like \h and \A.
- Generating boilerplate C code with pcre2_compile/pcre2_match or shell-ready pcre2grep commands from tested patterns.

## How it works

- Enter your PCRE2 pattern and optional test subject text into the input fields.
- Toggle execution flags such as caseless (i), multiline (m), dotall (s), extended (x), ungreedy (U), or global matching (g).
- Optionally provide a replacement string or enable Unicode character class matching (PCRE2_UCP emulation).
- Inspect the highlighted match results, named group captures, replacement output, and generated CLI/C integration snippets.

## Use cases

- PHP backend engineers testing complex preg_match and preg_replace rules with named capture groups.
- DevOps and system administrators drafting precise pcre2grep commands to parse server log files.
- C and systems developers generating starting boilerplate for pcre2_compile and pcre2_match implementations.

## Frequently asked questions

### Which named group syntaxes are supported?

The tester supports Python-style (?P...), Perl/Oniguruma style (?...), and single-quoted (?'name'...) formats, along with corresponding backreferences.

### How are atomic groups and possessive quantifiers evaluated?

They are translated using lookahead-capture mechanisms within the engine to prevent backtracking, replicating PCRE2 execution semantics.

### Does \d match all Unicode digits by default?

No. By default, \d, \w, and \s maintain ASCII-only PCRE2 semantics unless the Unicode character classes option is checked.

### What happens if I use an unsupported PCRE2 construct?

Constructs that cannot be evaluated accurately—such as recursion ((?R)), callouts, \K, \G, or backtracking control verbs—are detected and rejected with an explanatory message.

### Can this tool preview regular expression replacements?

Yes, entering a pattern into the optional replacement template field provides a live preview of the substituted output using capture references.

## Related tools

- [Java Regex Tester](https://elysiatools.com/en/tools/java-regex-tester): Test java.util.regex patterns online: (?…) named groups, possessive quantifiers and atomic groups, Pattern flags, ASCII vs UNICODE\_CHARACTER\_CLASS \\d semantics, and ready-to-paste Java code.
- [Regex Cheat Sheet](https://elysiatools.com/en/tools/regex-cheat-sheet): A searchable, localized cheat sheet for regular expression syntax — character classes, anchors, quantifiers, groups & references, lookarounds, escape sequences, and flags — with a built-in quick tester
- [Regex Debugger](https://elysiatools.com/en/tools/regex-debugger): Step through how a regular expression matches a string position by position: visualize match attempts, partial successes, backtracks, and captures — a learning tool for understanding regex behavior, not just the final result
- [Regex Tester](https://elysiatools.com/en/tools/regex-tester): Test regular expressions against text
- [Regex Benchmark](https://elysiatools.com/en/tools/regex-benchmark): Compare performance of different regex patterns, identify bottlenecks, and detect degenerate cases
- [C# Regex Tester (.NET)](https://elysiatools.com/en/tools/csharp-regex-tester): Test .NET/C# regular expressions online with named groups ((?…)), IgnoreCase/Multiline/Singleline options, match highlighting, capture-group tables, a ready-to-paste C# snippet and an IgnorePatternWhitespace preview.
- [Python Regex Tester (re module)](https://elysiatools.com/en/tools/python-regex-tester): Test Python re patterns online: (?P…) named groups, (?P=name) backreferences, VERBOSE patterns, findall behavior, and \\g replace templates — plus ready-to-paste Python code.
- [Regex Railroad Diagram Visualizer](https://elysiatools.com/en/tools/regex-railroad-diagram-visualizer): Render a regular expression as an SVG railroad (syntax) diagram showing literals, groups, alternations, and repetition, with capture-group numbering and flag explanations

## Samples

- [Regex Replace Samples](https://elysiatools.com/en/samples/regex-replace): Collection of common and useful regex replacement patterns for text transformation and data cleaning
- [Common Regex Patterns](https://elysiatools.com/en/samples/regex-samples): Commonly used regular expression patterns for validation and matching
- [Regex Pattern Alternatives](https://elysiatools.com/en/samples/regex-alternatives): Multiple ways to write the same regex pattern with different trade-offs in readability, performance, and accuracy
- [Regex Named Capture Groups](https://elysiatools.com/en/samples/regex-named-groups): Collection of regex patterns using named capture groups for extracting structured data from text. Named groups make patterns more readable and maintainable by assigning meaningful names to captured portions.
