mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Regex: Add substitution to regex and undefined checks
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>
This commit is contained in:
@@ -45,13 +45,14 @@ function getRegexedString(rawString, placement) {
|
||||
|
||||
// Runs the provided regex script on the given string
|
||||
function runRegexScript(regexScript, rawString) {
|
||||
if (!!(regexScript.disabled)) {
|
||||
if (!regexScript || !!(regexScript.disabled) || !regexScript?.findRegex || !rawString) {
|
||||
return;
|
||||
}
|
||||
|
||||
let match;
|
||||
let newString;
|
||||
const findRegex = regexFromString(regexScript.findRegex);
|
||||
console.log(regexScript.substituteRegex ? substituteParams(regexScript.findRegex) : regexScript.findRegex)
|
||||
const findRegex = regexFromString(regexScript.substituteRegex ? substituteParams(regexScript.findRegex) : regexScript.findRegex);
|
||||
while ((match = findRegex.exec(rawString)) !== null) {
|
||||
const fencedMatch = match[0];
|
||||
const capturedMatch = match[1];
|
||||
|
Reference in New Issue
Block a user