From 8a7519c6e75bc3d08dde528506363493225b9af6 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Thu, 11 Jan 2024 02:41:00 +0200 Subject: [PATCH] Replace match with $0 --- public/scripts/extensions/regex/engine.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/public/scripts/extensions/regex/engine.js b/public/scripts/extensions/regex/engine.js index 57d0e2517..358fc15ae 100644 --- a/public/scripts/extensions/regex/engine.js +++ b/public/scripts/extensions/regex/engine.js @@ -112,10 +112,17 @@ function runRegexScript(regexScript, rawString, { characterOverride } = {}) { // Run replacement. Currently does not support the Overlay strategy newString = rawString.replace(findRegex, function(match) { const args = [...arguments]; - const replaceString = regexScript.replaceString.replace('{{match}}', '$1'); + const replaceString = regexScript.replaceString.replace(/{{match}}/gi, '$0'); const replaceWithGroups = replaceString.replaceAll(/\$(\d)+/g, (_, num) => { - // match is found here + // Get a full match or a capture group const match = args[Number(num)]; + + // No match found - return the empty string + if (!match) { + return ''; + } + + // Remove trim strings from the match const filteredMatch = filterString(match, regexScript.trimStrings, { characterOverride }); // TODO: Handle overlay here