As opposed to making the match variable include the entire regex
match, overlay the replacement string over the regex match and splice
out whatever's already in the replacement string from the regex match.
This new strategy helps save time when editing messages since match
prefix and suffix phrases have a lower chance of being repeated on
every edit. The overlay strategy also preserves uniqueness if the user
decides to change something in the edited text.
However, overlay can cause issues especially with punctiation,
so the strategy isn't chosen by default when creating a new regex.
Signed-off-by: kingbri <bdashore3@proton.me>
Sometimes a user may want to substitute variables in the regex
itself rather than just matching those variables. This can be
optionally enabled in the editor.
In addition, try preventing crashes by checking for undefined
variables or null coalescing.
Signed-off-by: kingbri <bdashore3@proton.me>
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>
Regex is a method that is commonly used to find and replace parts
of a string using a single pattern. Add support for using regex in
SillyTavern which allows users to dynamically change various aspects
of the chatting experience.
Users are able to choose where a given regex script should apply
(both invasive and non-invasive options!). Invasive options alter
chat history while non-invasive alters markdown display for the
entire chat.
A new variable called {{match}} is added in regex scripts which
substitutes in the found match from the original find regex script.
There is a lot more that can be added to this extension, but for now,
this is enough.
Signed-off-by: kingbri <bdashore3@proton.me>