AUX_SEP_REGEX Pattern in Rime LMDG: How to Customize Auxiliary Code Separators

The AUX_SEP_REGEX constant in the amzxyz/rime-lmdg repository uses the pattern r'[;\[]' to split base pinyin from auxiliary codes at semicolons or opening square brackets, and modifying this regex in wanxiang-tools.py instantly updates delimiter behavior across the entire toolchain.

The rime-lmdg project implements an advanced input method engine that relies on auxiliary codes to disambiguate pinyin syllables. The AUX_SEP_REGEX regular expression defines exactly where the root syllable ends and the auxiliary suffix begins, making it the central configuration point for custom separator characters.

Default AUX_SEP_REGEX Pattern and Behavior

The current implementation in wanxiang-tools.py defines the separator pattern as:

AUX_SEP_REGEX = r'[;\[]'

This character class matches either a semicolon (;) or an opening square bracket ([). When processing input strings like ni;re or ni[re, the regex splits the segment at the first delimiter occurrence, extracting ni as the root pinyin and re as the auxiliary code.

The splitting logic uses Python's re.split module at line 60:

root = re.split(AUX_SEP_REGEX, seg)[0]
aux = seg[len(root)+1:]

The first line isolates the base pronunciation, while the second derives the auxiliary component from the remaining substring.

Where AUX_SEP_REGEX Is Used in the Codebase

The regex constant appears in multiple critical files across the repository:

  • wanxiang-tools.py: Defines AUX_SEP_REGEX at line 60 and implements the core splitting logic for auxiliary code processing.
  • rime固定或用户词典刷新为带辅助码编码.py: Imports and utilizes the regex at line 22 to parse dictionary entries containing auxiliary codes.
  • rime固定或用户词典刷新为带声调编码.py: Applies the same pattern for tone-encoded dictionary processing.

Because these scripts import the constant from the utility module, changing the definition in wanxiang-tools.py propagates automatically to all dependent tools.

Modifying AUX_SEP_REGEX for Custom Auxiliary Codes

Customizing the delimiter requires editing the character class to include or exclude specific characters. All downstream logic relies on this single constant, so the change applies instantly without additional code modifications.

Adding New Delimiters

To support multiple separator types while preserving defaults, append characters to the class. For example, to add a pipe (|) while keeping semicolons and brackets:

AUX_SEP_REGEX = r'[;\[|]'

This pattern now matches semicolons, opening brackets, or pipes, allowing inputs like ni|re to parse correctly.

Replacing Default Separators

To use completely custom delimiters such as colons or dashes, redefine the regex:

AUX_SEP_REGEX = r'[:\-]'

Note the escaped hyphen (\-) when placing it within the character class to avoid range interpretation. This configuration treats ni:re and ni-re as valid auxiliary code formats.

Practical Implementation Examples

Default behavior (semicolon separator):

from wanxiang_tools import AUX_SEP_REGEX
import re

seg = "ni;re"
root = re.split(AUX_SEP_REGEX, seg)[0]   # → 'ni'

aux = seg[len(root)+1:]                  # → 're'

print(root, aux)                         # Output: ni re

Custom behavior (colon and dash):


# In wanxiang-tools.py

AUX_SEP_REGEX = r'[:\-]'

seg = "ni:re"
root = re.split(AUX_SEP_REGEX, seg)[0]   # → 'ni'

aux = seg[len(root)+1:]                  # → 're'

Summary

  • The AUX_SEP_REGEX pattern r'[;\[]' splits pinyin from auxiliary codes using semicolons or opening brackets as delimiters.
  • Located in wanxiang-tools.py, this constant controls parsing behavior across the entire rime-lmdg toolchain including dictionary refresh scripts.
  • Modify the regex character class to add custom delimiters like colons, pipes, or hyphens by editing the single constant definition.
  • Changes apply immediately to re.split operations in rime固定或用户词典刷新为带辅助码编码.py and related modules without requiring additional updates.

Frequently Asked Questions

What is the default AUX_SEP_REGEX pattern in rime-lmdg?

The default pattern is r'[;\[]', which creates a character class matching either a semicolon (;) or an opening square bracket ([). This allows input strings like ni;re or ni[re to split correctly into root pinyin and auxiliary components according to the source code in wanxiang-tools.py.

How do I add a custom delimiter to AUX_SEP_REGEX?

Edit the character class in wanxiang-tools.py to include your desired character within the brackets. For example, change r'[;\[]' to r'[;\[|]' to add the pipe character (|) as a valid separator while preserving the original semicolon and bracket delimiters.

Which files need to be updated when changing AUX_SEP_REGEX?

Only wanxiang-tools.py requires modification, as this file defines the constant at line 60. Other scripts such as rime固定或用户词典刷新为带辅助码编码.py import this value from the utility module, so they automatically adopt the new pattern without manual edits.

Does modifying AUX_SEP_REGEX affect existing dictionary entries?

Yes, changing the regex alters how all input strings parse throughout the system. If you remove the semicolon (;) from the pattern, existing entries using that delimiter will fail to split correctly, treating the entire string including the separator as the root pinyin.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →