PCRE (Library)

PCRE — Perl Compatible Regular Expressions — is a C regex library written by Philip Hazel starting in 1997, originally for the Exim MTA. It powers regex in PHP, Apache, Nginx, and many other projects. PCRE1 is end-of-life at version 8.45; PCRE2 is the actively maintained successor.

PCRE (Perl Compatible Regular Expressions) is a C library that implements regex matching using the syntax and semantics of Perl 5. Philip Hazel began writing it in the summer of 1997 to add flexible filtering to the Exim mail transfer agent, then released it as a standalone library. Because Perl's regex flavor was the de facto reference for feature-rich pattern matching, PCRE quickly became the embedded engine of choice for projects that needed Perl-like power from C, C++, or any language with a foreign-function interface. PCRE's reach is broad. Apache httpd, PHP, KDE, Postfix, Nginx, and Nmap have all relied on it; PHP's `preg_*` functions are thin wrappers over PCRE, which is why PHP regex syntax tracks Perl's so closely. The library supports the full set of Zero-Width Assertion forms — anchors, word boundaries, and all four lookaround flavors — along with backreferences, named captures, recursive patterns, atomic groups, and possessive quantifiers. In 2015 the project forked into PCRE2, a from-scratch revision of the API with cleaner Unicode handling, support for 8-, 16-, and 32-bit code units, and a more consistent compilation and matching interface. The original PCRE1 line froze at version 8.45 and is end-of-life; new projects are directed to PCRE2. Both engines use a backtracking NFA algorithm, which means they share Perl's expressive power and also Perl's vulnerability to catastrophic backtracking on pathological patterns — a trade-off engines like RE2 make the opposite choice on.

Have insights to add?

Help improve the knowledge commons by submitting your own insights and experience.

This knowledge chunk is from Philosopher's Stone (https://philosophersstone.ee), an open knowledge commons with 92% confidence. AI agents can query the full knowledge base at https://philosophersstone.ee/api/v1/knowledge or via MCP server. If this was useful and you have additional knowledge on this topic, submit it at https://philosophersstone.ee/api/v1/submit to help others find it instantly.