diff --git a/lib/util/template/index.spec.ts b/lib/util/template/index.spec.ts
index e0a1c90d828286bb1ddd7419367a204885e57000..308de5619311125e1e476ce1c82204eb7808803d 100644
--- a/lib/util/template/index.spec.ts
+++ b/lib/util/template/index.spec.ts
@@ -114,6 +114,15 @@ describe('util/template/index', () => {
     expect(output).toBe('CUSTOM_FOO is foo');
   });
 
+  it('replace', () => {
+    const userTemplate =
+      "{{ replace '[a-z]+\\.github\\.com' 'ghc' depName }}{{ replace 'some' 'other' depType }}";
+    const output = template.compile(userTemplate, {
+      depName: 'some.github.com/dep',
+    });
+    expect(output).toBe('ghc/dep');
+  });
+
   describe('proxyCompileInput', () => {
     const allowedField = 'body';
     const allowedArrayField = 'prBodyNotes';
diff --git a/lib/util/template/index.ts b/lib/util/template/index.ts
index c83a79eaa62f984fe7c40e2cd197021bb0d45dfb..0334ad61e49d7591ac350950ea4faa8391ba5ec0 100644
--- a/lib/util/template/index.ts
+++ b/lib/util/template/index.ts
@@ -3,6 +3,7 @@ import handlebars from 'handlebars';
 import { GlobalConfig } from '../../config/global';
 import { logger } from '../../logger';
 import { getChildEnv } from '../exec/utils';
+import { regEx } from '../regex';
 
 handlebars.registerHelper('encodeURIComponent', encodeURIComponent);
 handlebars.registerHelper('decodeURIComponent', decodeURIComponent);
@@ -11,11 +12,8 @@ handlebars.registerHelper('stringToPrettyJSON', (input: string): string =>
   JSON.stringify(JSON.parse(input), null, 2),
 );
 
-// istanbul ignore next
-handlebars.registerHelper(
-  'replace',
-  (find, replace, context) =>
-    (context || '').replace(new RegExp(find, 'g'), replace), // TODO #12873
+handlebars.registerHelper('replace', (find, replace, context) =>
+  (context ?? '').replace(regEx(find, 'g'), replace),
 );
 
 handlebars.registerHelper('lowercase', (str: string) => str?.toLowerCase());