Expand description
RegexSolver treats regular expressions as the sets of strings they match, so you can intersect, subtract, compare, complement, repeat and enumerate them, then 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.
The rest follows from regular-language theory. Patterns are parsed with
regex-syntax, and a
construct that would change matching in a way the engine cannot represent
returns an EngineError rather than being applied incorrectly:
- Backreferences (
\1,\2, …) go beyond regular languages, as do look-around assertions ((?=...),(?<=...)). - Anchors and word boundaries: since matching is already full-string, a
leading
^/\Aand a trailing$/\zare accepted as redundant no-ops. Anchors anywhere else, and word boundaries (\b,\B), would constrain matching in ways a regular language cannot express, so they returnEngineError::UnsupportedRegexFeature. - Inline flags (
(?i),(?m),(?s),(?x)) returnEngineError::UnsupportedRegexFeature: the engine matches character ranges uniformly and cannot honor them, and dropping them silently would diverge from standard regex semantics ((?i)abcwould stop matchingABC). - All quantifiers are greedy: as sets of strings,
a*anda*?are the same language, so ungreedy markers (*?,+?,??) are accepted and ignored. - The empty language (matching no string at all) is written
[], an empty character class. It is distinct from the empty string"".
Character classes are resolved against a compiled-in copy of the Unicode
character database, currently Unicode 16.0.0
(regex_charclass::UCD_VERSION). A class is printed back in canonical
form, so \p{Lu} comes back as \p{Uppercase_Letter} and
\p{Decimal_Number} as \d.
§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 foru32, or infinite. - error
- The
EngineErrortype returned by fallible operations. - execution_
profile - Resource limits: the thread-local
ExecutionProfilegoverning timeouts, state caps, and implicit determinization. - fast_
automaton - Finite automata:
FastAutomatonand its building blocks (conditions, spanning sets). - regex
- The parsed-pattern AST:
RegularExpression.
Structs§
- NoHash
Hasher - A no-op
Hasherfor 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. - String
Generator - Lazy iterator over the strings matched by a
Term, created byTerm::iter_strings.
Enums§
- Term
- A regular language, held either as a parsed
RegularExpressionor as aFastAutomaton. Every operation runs on whichever representation is cheaper for it and converts only when it has to.
Type Aliases§
- Char
Range - 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_statesand related inspection methods.