Regex: Add trimStrings option

Sometimes the matched regex string needs to be pruned before
replacement. Add a method for the user to provide strings which
globally trims a regex match before any replacement is done.

Example without trim:
input - <Manami's thoughts: This is a thought>
regex - /<([^>]*)>/g
output - <Manami's thoughts: Manami's thoughts: This is a thought>

With trim:
input - <Manami's thoughts: This is a thought>
regex - /<([^>]*)>/g
trim - ["{{char}}'s thoughts: "]
output - <Manami's thoughts: This is a thought>

Signed-off-by: kingbri <bdashore3@proton.me>
This commit is contained in:
kingbri
2023-07-04 02:00:03 -04:00
parent ef7aa3941b
commit ee6a6603a3
3 changed files with 44 additions and 10 deletions

View File

@@ -87,9 +87,10 @@ async function onRegexEditorOpenClick(existingId) {
editorHtml.find(`.regex_script_name`).val(existingScript.scriptName);
editorHtml.find(`.find_regex`).val(existingScript.findRegex);
editorHtml.find(`.regex_replace_string`).val(existingScript.replaceString);
editorHtml.find(`.regex_trim_strings`).val(existingScript.trimStrings?.join("\n") || []);
editorHtml
.find(`input[name="disabled"]`)
.prop("checked", existingScript.disabled);
.prop("checked", existingScript.disabled ?? false);
editorHtml
.find(`input[name="run_on_edit"]`)
.prop("checked", existingScript.runOnEdit);
@@ -116,13 +117,14 @@ async function onRegexEditorOpenClick(existingId) {
scriptName: editorHtml.find(".regex_script_name").val(),
findRegex: editorHtml.find(".find_regex").val(),
replaceString: editorHtml.find(".regex_replace_string").val(),
trimStrings: editorHtml.find(".regex_trim_strings").val().split("\n").filter((e) => e.length !== 0) || [],
placement:
editorHtml
.find(`input[name="replace_position"]`)
.filter(":checked")
.map(function() { return parseInt($(this).val()) })
.get()
.filter((e) => e !== NaN) ?? [],
.filter((e) => e !== NaN) || [],
disabled:
editorHtml
.find(`input[name="disabled"]`)