Skip to main content

SillyTavern regex: a display-only text cleanup recipe

Remove a literal line prefix with one small regex, inspect tested examples and nonmatches, and separate display cleanup from prompts and saved chat history.

Updated 5 min readMarkdown

Use this SillyTavern regex recipe to remove an exact [Scene] label from the beginning of a line while keeping the sentence after it. The task is deliberately small: plain-text prefix cleanup, not a Markdown parser or a story-state system.

Checked November 20, 2026 UTC: our local JavaScript fixture passed nine cases and a whitespace counterexample. We have not installed SillyTavern or run its Test Mode, chat or model. The strings are authored examples, not generated replies. EchoMelon publishes this guide and operates a competing character-chat product.

Start with the exact expression

/^\[Scene\][ \t]*/gm

Replace the match with an empty string. Do not type quotation marks or the word “empty” into the replacement field.

Read the expression in pieces:

  • ^ with m restricts the match to each line's beginning.
  • \[Scene\] matches the literal bracketed label, with that capitalization.
  • [ \t]* consumes zero or more spaces or tabs immediately after it.
  • g allows matches on multiple lines; there is no case-insensitive i flag.

Our fixture applies the pattern through JavaScript's string replacement operation. That operation returns a new string; it does not establish how an application stores or displays it.

Choose the documented display scope

The official Regex guide places this built-in extension in Extensions. With a disposable character active, create a Scoped rule:

Setting Use
Name Scene prefix display cleanup
Find Regex /^\[Scene\][ \t]*/gm
Replace With; Trim Out Both empty
Affects AI Response only
Ephemerality Display option on; Alter Outgoing Prompt off
Run on Edit Off for this exercise
Macros in Find Regex Don't Substitute

Use Test Mode, pasting a sample into Input and comparing Output; no new generation is needed. Save only after the samples match. If controls differ, check your installed version and documentation rather than substituting Global or a default mode.

The documented default with neither Ephemerality box checked directly rewrites stored JSONL irreversibly. Display-only changes the view, leaving the chat file and outgoing context unchanged. It does not erase the original text or keep it from the model. These are documented settings, not behavior we verified in the app.

Compare the tested input and output

Input: two marked lines

[Scene] The blue suitcase is beside the ticket machine.
[Scene]	The bus leaves at 18:40.

The second label is followed by a tab. The tested result is:

The blue suitcase is beside the ticket machine.
The bus leaves at 18:40.

Only the prefixes and following horizontal whitespace disappeared. The suitcase's location and departure time stayed the same. Removing a label has not moved an object, advanced the clock or made a character choose anything.

The same fixture checked the first line by itself, with the same resulting sentence. It also preserved Windows-style CRLF line endings. In escaped notation, where \r\n represents that line ending and \t a tab:

Input:  "[Scene] First line.\r\n[Scene]\tSecond line."
Output: "First line.\r\nSecond line."

These strings describe actual replacement observations, not an observed SillyTavern preview.

Keep the nonmatches intentional

Each of these tested inputs remained unchanged:

Mara, 43, says, "[Scene] is the label on the draft."
[scene] The clock reads 18:35.
 [Scene] The clock reads 18:35.

The first label is inside a sentence. The second has different capitalization. The third has a space before the opening bracket. That leading space is part of the example; it is not an alignment mistake.

Do not broaden the expression just because one of these survives. First decide whether it should survive. A literal label mentioned in dialogue is different from the prefix you intended to hide.

Preserve the empty line

This tested input contains a line consisting only of the label:

Waiting.
[Scene]
The bus is late.

The result retains its line break, leaving a blank line:

Waiting.

The bus is late.

The counterexample replaced [ \t]* with the broader \s*. On this input, that version produced:

Waiting.
The bus is late.

It consumed the newline after the label. Use horizontal whitespace when preserving that separation is part of the task. A cleaner-looking result is not necessarily the result you specified.

Know what the pattern does not understand

Code fences are not protected. The fixture's input was:

```text
[Scene] Example text.
```

Its output was:

```text
Example text.
```

The pattern sees the same line prefix inside the fence. It does not recognize “an example the reader wants to keep literal.” If that distinction matters, this recipe is unsuitable without a separate approach.

One pass also removes only one prefix per line:

Input:  [Scene] [Scene] The bus is late.
Output: [Scene] The bus is late.

The remaining prefix is not recursively removed during that replacement call. Do not describe the recipe as generally idempotent: another pass is another operation, not proof that the text will stay unchanged.

Diagnose the smallest mismatch

Compare an unexpected result with the closest example above. Check exact capitalization, the first character on the line, literal brackets, the flags and whether the replacement is truly blank. Then inspect the selected source, active character scope and any competing rules. Change one condition at a time and keep the original sample beside the result.

A passing string fixture supports this narrow cleanup only. It supplies no evidence of better memory, token savings, privacy or model compliance, and cannot reverse earlier persistent edits.

For scene facts rather than presentation, use a plain-text status panel. For the frontend and backend distinction, read our SillyTavern roleplay review. To find a character for another story, browse EchoMelon's English character directory.

The useful split is between a display-only rule and one that rewrites the stored file. The recipe is narrow on purpose: it removes a literal [Scene] at the start of a line, plus the spaces or tabs that follow, and leaves the rest of the sentence. Using only horizontal whitespace, rather than a broader whitespace class, is the detail that keeps a line that was only the label from collapsing into its neighbors. The cases that stay unchanged — a mention inside a sentence, different capitalization, or a space before the bracket — also make sense once the intent is this exact prefix, not anything that looks similar. One pass leaving a second prefix on the same line is a fair limit to state up front.