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

> Customize Rime LMDG auxiliary codes by modifying the AUX_SEP_REGEX pattern in wanxiang-tools.py. Learn how this regex splits pinyin and update delimiters instantly.

- Repository: [amzxyz/rime-lmdg](https://github.com/amzxyz/rime-lmdg)
- Tags: how-to-guide
- Published: 2026-02-24

---

**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`](https://github.com/amzxyz/rime-lmdg/blob/main/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`](https://github.com/amzxyz/rime-lmdg/blob/main/wanxiang-tools.py) defines the separator pattern as:

```python
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:

```python
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`](https://github.com/amzxyz/rime-lmdg/blob/main/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`](https://github.com/amzxyz/rime-lmdg/blob/main/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:

```python
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:

```python
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):**

```python
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):**

```python

# 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`](https://github.com/amzxyz/rime-lmdg/blob/main/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`](https://github.com/amzxyz/rime-lmdg/blob/main/wanxiang-tools.py).

### How do I add a custom delimiter to AUX_SEP_REGEX?

Edit the character class in [`wanxiang-tools.py`](https://github.com/amzxyz/rime-lmdg/blob/main/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`](https://github.com/amzxyz/rime-lmdg/blob/main/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.