regexmigrationpcre

Regex differences between PCRE and PCRE2


We're considering moving from PCRE to PCRE2 as our internal regex engine. Only the regex syntax itself is exposed to our users, so the library APIs differences are not an issue to our uses. However, we will have to document any change in behaviour.

Plenty of websites discuss the API differences, but I've not found any that list practical differences there in the regex symtax. While I do know that [\w-_] means the same as [\w\-_] in PCRE but is invalid in PCRE2, I suspect other differences exist.

In what ways do the regexes of PCRE2 differ from those of PCRE?


Solution

  • Compiled differences between PCRE v8.36 and PCRE2 10.39

    I have compiled a list of changes that are possible issues one could encounter when converting from pcre to pcre2. I have excluded various overflows, underflows, segmentation violations, and assorted errors the pattern could encounter in pcre.

    Pcre2 has a version checking pattern. You may check the version in applications with /(?(VERSION>=10)yes|no)/ matching against "yesno".

    Possible breaking changes: