Text Rules (Regex)

Learn how to automatically replace, remove, and format messages in Ryokan using text rules, regular expressions, templates, and a live preview.

Ryokan's text rules let you automatically modify messages before they are displayed or sent to the AI.

You can use them to remove unwanted phrases, replace recurring terms, or clean up unnecessary blank lines.

The original messages remain unchanged in storage.

Creating a Text Rule

Open Settings → Text rules and select Create rule.

You can start with one of the available templates:

  • Remove character name at the beginning: Removes prefixes such as “Character:” from the beginning of a line.
  • Replace text: Replaces specific words or phrases with something else.
  • Remove text: Removes unwanted text entirely.
  • Clean up extra blank lines: Reduces excessive consecutive blank lines.

Alternatively, select Custom rule to create your own rule from scratch.

All templates can be edited afterward.

Finding and Replacing Text

Each rule consists of a search pattern and a replacement.

Under Find, enter the text you want to match. Under Replace with, specify what should appear instead.

Example:

Find: Hello

Replace with: Good morning

The message “Hello, how are you?” becomes “Good morning, how are you?”.

Leaving Replace with empty removes the matching text entirely.

Using Regular Expressions

Ryokan supports regular expressions (regex), allowing you to match patterns rather than just exact words.

For example, the pattern ^Character:\s* removes a character-name prefix written in that format.

Under Advanced, you can configure additional regex flags:

  • g – Replace all matches.
  • i – Ignore uppercase and lowercase differences.
  • m – Treat each line's beginning and end separately.
  • s – Allow the dot to match newline characters.

Replacement groups such as $1 and $2, as well as named groups, are also supported.

Ryokan uses JavaScript regular expressions. Enter patterns without surrounding slashes.

Choosing Where Rules Apply

Under Apply to, you can specify which types of content a rule should affect.

The Which content? options include:

  • My messages: Messages you've written yourself.
  • AI messages: Responses generated by the AI.
  • Reasoning: Embedded thinking and channel sections.
  • Lorebook content: Information from your World Info entries.

Under Where should it apply?, you can choose how the rule is used.

What I see modifies how text appears inside Ryokan. The stored original remains unchanged.

What the AI sees modifies the text Ryokan prepares for AI requests. For example, you can replace certain terms in the AI input without editing the original message.

Both options can be enabled simultaneously.

Note: Reasoning rules apply to embedded thinking sections within text. They do not reveal native thinking tokens from an AI provider.

Testing Rules with the Live Preview

The rule editor includes a Live preview.

Enter any text under Example text. Ryokan immediately displays the transformed result and the number of matches found.

Invalid regex expressions produce an error and cannot be applied.

The preview only tests the rule you're currently editing. Other existing rules are not included in the preview.

Managing and Reordering Rules

You can edit, delete, or disable individual rules from the overview.

Rules can also be reordered using drag and drop. On mobile devices, press and hold a rule to move it.

Order matters: Ryokan processes enabled rules from top to bottom. One rule may therefore change the text that the next rule receives.

When you're finished, select Save in Settings to persist your changes.


Tip: Start with one of the built-in templates and test it using the live preview. Simple text replacements don't require complicated regular expressions.