Skip to content

Replace PCRE1 with PCRE2#4939

Open
Lpsd wants to merge 12 commits into
multitheftauto:masterfrom
Lpsd:pcre2
Open

Replace PCRE1 with PCRE2#4939
Lpsd wants to merge 12 commits into
multitheftauto:masterfrom
Lpsd:pcre2

Conversation

@Lpsd

@Lpsd Lpsd commented Jun 10, 2026

Copy link
Copy Markdown
Member

Summary

Replaces the outdated PCRE1 with PCRE2 10.47 from https://github.com/PCRE2Project/pcre2

With the exception of a startup check in Server/mods/deathmatch/logic/CGame.cpp, the only usage of PCRE is for the Lua implementation of pregFind, pregMatch and pregReplace functions. A testing resource is provided below with 40 test cases.

There is no C++ wrapper in PCRE2, so we now have our own under Shared/pcrecpp_compat.h

Motivation

PCRE1 is not maintained anymore

Test plan

Test resource: pcre.zip
Simply start the resource and all 40 tests will run with results output in console (server).

It's worth noting that 5 of the tests don't actually work with PCRE1, however they are resolved in PCRE2 -- or rather by the new C++ wrapper. This isn't a concern for backwards compatibility since these cases weren't working properly (or at all) previously.

# Function Test Expected PCRE1 PCRE2
10 pregFind "line1\nline2" / "^line2" / "m" true
13 pregFind "a\nb" / "a.b" false
16 pregFind "Γειά" / "\w+" / "u" true
27 pregMatch "John Doe" / "(\w+) (\w+)" {"John Doe"}
35 pregReplace "a/b" / "/" / "\" "a\b"
  • 10, 13 - Old pcrecpp wrapper failed to pass PCRE_MULTILINE / PCRE_DOTALL flags through to pcre_compile. The C API supported them, but the C++ wrapper silently dropped them.
  • 16 - Old set_utf8(true) only set PCRE_UTF8 without PCRE_UCP, so \w matched only ASCII even with UTF-8 enabled. Our compat wrapper correctly enables both PCRE2_UTF + PCRE2_UCP.
  • 27 - Old FindAndConsume returned only the first capture group ("John") instead of the full match ("John Doe") for patterns with parenthesized groups.
  • 35 - Old pcrecpp used \ for backreferences in replacement strings, causing a literal \ to be consumed as an escape. PCRE2's pcre2_substitute uses $ for backreferences, so literal \ passes through correctly.

Checklist

  • Your code should follow the coding guidelines.
  • Smaller pull requests are easier to review. If your pull request is beefy, your pull request should be reviewable commit-by-commit.

@Lpsd Lpsd added the upstream Related to vendor library label Jun 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

upstream Related to vendor library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant