Add support for named regex capture groups. (#4397) * Update UpdateAndStart.bat * regex named capture group * Add row to replace with textarea * Move checkbox up * Revert toggle and syntax preferences * Remove comment --------- Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>

fd00b5a5b8e9536349661b69fe46915cf8372b68

zengls <94688592+zeroDtree@users.noreply.github.com>

Signed
2 files changed, +10 -6Showing whitespace changes
public/scripts/extensions/regex/editor.html+1 -1
@@ -61,7 +61,7 @@
6161 <small data-i18n="Replace With">Replace With</small>
6262 </label>
6363 <div>
6464 <textarea class="regex_replace_string text_pole wide100p textarea_compact" data-i18n="[placeholder]ext_regex_replace_string_placeholder" placeholder="Use {{match}} to include the matched text from the Find Regex or, $1, $2, etc. for numbered capture groups, or $&lt;name&gt; for named capture groups." rows="23"></textarea>
6565 </div>
6666 </div>
6767 <div class="flex1">
public/scripts/extensions/regex/engine.js+9 -5
@@ -163,9 +163,15 @@ function runRegexScript(regexScript, rawString, { characterOverride } = {}) {
163163 newString = rawString.replace(findRegex, function (match) {
164164 const args = [...arguments];
165165 const replaceString = regexScript.replaceString.replace(/{{match}}/gi, '$0');
166166 const replaceWithGroups = replaceString.replaceAll(/\$(\d+)|\$<([^>]+)>/g, (_, num, groupName) => {
167- // Get a full match or a capture group
167+ if (num) {
168- const match = args[Number(num)];
168+ // Handle numbered capture groups ($1, $2, etc.)
169+ match = args[Number(num)];
170+ } else if (groupName) {
171+ // Handle named capture groups ($<name>)
172+ const groups = args[args.length - 1];
173+ match = groups && typeof groups === 'object' && groups[groupName];
174+ }
169175
170176 // No match found - return the empty string
171177 if (!match) {
@@ -175,8 +181,6 @@ function runRegexScript(regexScript, rawString, { characterOverride } = {}) {
175181 // Remove trim strings from the match
176182 const filteredMatch = filterString(match, regexScript.trimStrings, { characterOverride });
177183
178- // TODO: Handle overlay here
179-
180184 return filteredMatch;
181185 });
182186