From f5595f334c00f156d4c9f364e6470ceba09a953b Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@arkins.net>
Date: Sat, 8 Apr 2023 10:38:43 +0200
Subject: [PATCH] feat: RENOVATE_X_IGNORE_RE2 (#21391)

---
 docs/usage/self-hosted-experimental.md |  4 ++++
 lib/util/regex.ts                      | 20 +++++++++++---------
 2 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/docs/usage/self-hosted-experimental.md b/docs/usage/self-hosted-experimental.md
index 5637573510..5945938bef 100644
--- a/docs/usage/self-hosted-experimental.md
+++ b/docs/usage/self-hosted-experimental.md
@@ -44,6 +44,10 @@ See [issue 8660](https://github.com/renovatebot/renovate/issues/8660) for backgr
 
 Suppress the default warning when a deprecated version of Node.js is used to run Renovate.
 
+## `RENOVATE_X_IGNORE_RE2`
+
+Skip initializing `RE2` for regular expressions and instead use Node-native `RegExp` instead.
+
 ## `RENOVATE_X_PLATFORM_VERSION`
 
 If set, Renovate will use this string as GitLab server version instead of checking via the GitLab API.
diff --git a/lib/util/regex.ts b/lib/util/regex.ts
index fd227ec2da..8396102e42 100644
--- a/lib/util/regex.ts
+++ b/lib/util/regex.ts
@@ -8,16 +8,18 @@ let RegEx: RegExpConstructor;
 
 const cache = new Map<string, RegExp>();
 
-try {
-  const RE2 = re2();
-  // Test if native is working
-  new RE2('.*').exec('test');
-  logger.debug('Using RE2 as regex engine');
-  RegEx = RE2;
-} catch (err) {
-  logger.warn({ err }, 'RE2 not usable, falling back to RegExp');
-  RegEx = RegExp;
+if (!process.env.RENOVATE_X_IGNORE_RE2) {
+  try {
+    const RE2 = re2();
+    // Test if native is working
+    new RE2('.*').exec('test');
+    logger.debug('Using RE2 as regex engine');
+    RegEx = RE2;
+  } catch (err) {
+    logger.warn({ err }, 'RE2 not usable, falling back to RegExp');
+  }
 }
+RegEx ??= RegExp;
 
 export function regEx(
   pattern: string | RegExp,
-- 
GitLab