SillyTavern/SillyTavern · warning · Error

Invalid Find Regex

Error message

Invalid Find Regex

What it means

Thrown in the regex script editor's live Find Regex info-block updater when regexFromString(findRegex) returns falsy for the currently typed pattern. Unlike 56, this is interactive UI feedback — the message is shown via setInfoBlock as an error hint, not propagated as an exception. It signals the in-editor pattern is invalid.

Source

Thrown at public/scripts/extensions/regex/index.js:1358

 * @param {JQuery<HTMLElement>} editorHtml The editor HTML
 */
function updateInfoBlock(editorHtml) {
    const infoBlock = editorHtml.find('.info-block').get(0);
    const infoBlockFlagsHint = editorHtml.find('#regex_info_block_flags_hint');
    const findRegex = String(editorHtml.find('.find_regex').val());

    infoBlockFlagsHint.hide();

    // Clear the info block if the find regex is empty
    if (!findRegex) {
        setInfoBlock(infoBlock, t`Find Regex is empty`, 'info');
        return;
    }

    try {
        const regex = regexFromString(findRegex);
        if (!regex) {
            throw new Error(t`Invalid Find Regex`);
        }

        const flagInfo = [];
        flagInfo.push(regex.flags.includes('g') ? t`Applies to all matches` : t`Applies to the first match`);
        flagInfo.push(regex.flags.includes('i') ? t`Case insensitive` : t`Case sensitive`);

        setInfoBlock(infoBlock, flagInfo.join('. '), 'hint');
        infoBlockFlagsHint.show();
    } catch (error) {
        setInfoBlock(infoBlock, error.message, 'error');
    }
}

// Common settings migration function. Some parts will eventually be removed
// TODO: Maybe migrate placement to strings?
function migrateSettings() {
    let performSave = false;

View on GitHub (pinned to 8172dcd0ee)

Solutions

  1. Complete/fix the pattern so it compiles in JS (flags limited to gimsuyuUAX).
  2. Remove unsupported flags or stray delimiter slashes.
  3. Test the pattern in a JS console first: new RegExp(...) or regexFromString(...).
  4. Clear the field to reset the hint (empty input is treated as info, not error).

Example fix

// before
findRegex: "foo/xyz"

// after
findRegex: "/foo/gi"
Defensive patterns

Strategy: validation

Validate before calling

import { regexFromString } from '../../../../utils.js';
const re = regexFromString(findRegex);
if (!re) {
    setInfoBlock(infoBlock, 'Invalid Find Regex', 'error');
    return;
}

Type guard

const isValidFindRegex = (input) => typeof input !== 'string' || input.length === 0 || Boolean(regexFromString(input));

Prevention

When it happens

Trigger: Typing an incomplete or malformed pattern in the Find Regex field (trailing slash with invalid flags, unclosed character class, unsupported flag); pasting a pattern with mismatched delimiters.

Common situations: Iteratively authoring a regex and hitting an intermediate invalid state; using PCRE-specific flags the JS engine rejects.

Related errors


AI-assisted analysis of SillyTavern/SillyTavern@8172dcd0ee (2026-08-13). Data as JSON: /api/errors/fc0b567ee5994aaf. Report an issue: GitHub.