Skip to main content

Crate regexsolver

Crate regexsolver 

Source
Expand description

RegexSolver treats regular expressions as the sets of strings they match, so you can intersect, subtract, compare, complement, repeat, and enumerate them — and convert the result back into a regex pattern.

§Quick start

Term is the main entry point: it wraps either a RegularExpression or a FastAutomaton and picks the cheaper representation for each operation.

use regexsolver::Term;

let a: Term = "(ab|xy){2}".parse()?;
let b: Term = ".*xy".parse()?;

// Which strings match BOTH patterns? Get the answer back as a regex:
let both = a.intersection([&b])?;
assert_eq!(both.to_pattern()?, "(ab|xy)xy");

// Matching is anchored (whole-string):
assert!(both.matches("abxy")?);

§Semantics

RegexSolver implements pure regular languages, which differs from a typical regex engine in two ways: matching is always anchored (a pattern describes whole strings, so abc matches only "abc"), and . matches any character including line feed. Constructs that a regular language can’t represent — backreferences, look-around, inline flags, and anchors/word boundaries in non-redundant positions — return an EngineError rather than being applied incorrectly. See the crate README for the full list.

§Bounding execution

Automaton operations can blow up on adversarial input, so a thread-local ExecutionProfile can cap runtime and state count and control implicit determinization; hitting a limit returns a specific EngineError instead of hanging.

§Modules

Most users only need Term. The lower-level building blocks live in regex (the parsed-pattern AST), fast_automaton (finite automata), execution_profile (resource limits), cardinality, and error.

Re-exports§

pub use regex_charclass;

Modules§

cardinality
Cardinality of a language (Cardinality): a finite count, a count too large for u32, or infinite.
error
The EngineError type returned by fallible operations.
execution_profile
Resource limits: the thread-local ExecutionProfile governing timeouts, state caps, and implicit determinization.
fast_automaton
Finite automata: FastAutomaton and its building blocks (conditions, spanning sets).
regex
The parsed-pattern AST: RegularExpression.

Structs§

NoHashHasher
A no-op Hasher for integer keys that are already well distributed, such as state ids: the key’s value is used as the hash directly. Only the integer key types it is implemented for can be hashed with it; anything else does not compile.
StringGenerator
Lazy iterator over the strings matched by a Term, created by Term::iter_strings.

Enums§

Term
Represents a term that can be either a regular expression or a finite automaton. This term can be manipulated with a wide range of operations.

Type Aliases§

CharRange
A set of character ranges (the transition-label alphabet type), re-exported from regex-charclass.
IntSet
A hash set of integer state ids using a no-op hasher (the hasher is fast because state ids are already well-distributed small integers). Returned by FastAutomaton::accept_states and related inspection methods.