To support the rapid search functionality (s command / search_rules.sh), we use a helper script that automatically annotates regex patterns with human-readable examples.
Our FUZZY_MAP.py files contain complex regular expressions. To make them searchable via fuzzy finders (fzf) without needing to understand the raw regex, we add # EXAMPLE: comments above the patterns.
Before:
('CreditCard', r'\b(?:\d[ -]*?){13,16}\b', ...)After (Auto-generated):
# EXAMPLE: 1234-5678-9012-3456
('CreditCard', r'\b(?:\d[ -]*?){13,16}\b', ...)We provide a Python script that scans all FUZZY_MAP.py and FUZZY_MAP_pre.py files and generates these examples automatically.
The script requires the exrex library to generate random matches for complex regexes.
pip install exrexRun the script from the project root:
python3 tools/map_tagger.py- Create or Edit a Map file (e.g., adding new rules).
- Run the tagger script.
- Interactive Mode:
- The script will show you a generated suggestion.
- Press
ENTERto accept it. - Type
sto skip. - Type
sa(skip all) if you want to skip all remaining patterns that fail generation.
- Commit the changes.
Note: The script ignores existing
# EXAMPLE:tags, so it is safe to run repeatedly.