mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
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:
@@ -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"]`)
|
||||
|
Reference in New Issue
Block a user