🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

rector

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rector

Regex generator that derives optimized patterns from example strings.

pipPyPI
Version
0.1.9
Maintainers
1

rector — Regex Generator

Rector turns example strings into optimized regular expressions you can reuse in search, validation, or routing rules. It ships with a trie-based engine that produces compact, deterministic patterns (also used by the CLI).

Installation

pip install rector

Library usage

from rector import TrieRegexGenerator

# Build a minimal trie-based pattern for larger sets or ranges
numbers = (
    TrieRegexGenerator()
    .add_examples([str(n) for n in range(10, 1000)])
    .generate()
)
assert numbers.pattern == "^[1-9][0-9]{1,2}$"

# Generate from small fixed-length samples
words = TrieRegexGenerator().add_examples(["cat", "car", "cap"]).generate()
assert words.pattern == r"^ca[prt]$"

CLI

Pipe examples to rector and it prints the generated pattern to stdout:

printf "cat\ncar\ncap\n" | rector
# -> ^ca[prt]$

The CLI anchors patterns by default and exits with status 1 if no stdin input is provided. Use --dense-threshold to adjust when near-contiguous character sets are collapsed into ranges (accepts fractions.Fraction strings like 3/4 or 0.6; default when flag is present without a value: 8/10).

Behavior notes

  • Patterns anchor to start/end unless you pass anchor_start=False or anchor_end=False.
  • Examples must be strings; TrieRegexGenerator raises TypeError otherwise.
  • TrieRegexGenerator builds a trie, minimizes it, and compacts ranges/quantifiers (using the density threshold for near-contiguous classes); it also accepts empty lines as valid examples.

Keywords

bdd

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts