pub struct RegexBuilder { /* private fields */ }Expand description
A builder for configuring and compiling a regex.
Implementations§
Source§impl RegexBuilder
impl RegexBuilder
Sourcepub fn pattern(self, pattern: &str) -> Self
pub fn pattern(self, pattern: &str) -> Self
Set the pattern to match.
§Example
use regexr::Regex;
let re = Regex::builder()
.pattern(r"\d+")
.build()
.unwrap();Sourcepub fn engine_type(self, engine_type: EngineType) -> Self
pub fn engine_type(self, engine_type: EngineType) -> Self
Force a specific engine type.
This method provides a unified API for forcing engine selection, matching the bytes mode API.
§Example
use regexr::Regex;
use regexr::engine::EngineType;
let re = Regex::builder()
.pattern(r"\d+")
.engine_type(EngineType::Vm)
.build()
.unwrap();Sourcepub fn vm(self) -> Self
pub fn vm(self) -> Self
Force use of the VM (backtracking) engine.
The VM engine supports all regex features including captures and lookarounds.
Sourcepub fn case_insensitive(self, yes: bool) -> Self
pub fn case_insensitive(self, yes: bool) -> Self
Enable case-insensitive matching.
Sourcepub fn multi_line(self, yes: bool) -> Self
pub fn multi_line(self, yes: bool) -> Self
Enable multi-line mode (^ and $ match line boundaries).
Sourcepub fn dot_matches_newline(self, yes: bool) -> Self
pub fn dot_matches_newline(self, yes: bool) -> Self
Make . match newlines.
Sourcepub fn size_limit(self, limit: usize) -> Self
pub fn size_limit(self, limit: usize) -> Self
Set the size limit for the compiled regex.
Sourcepub fn prefilter(self, enable: bool) -> Self
pub fn prefilter(self, enable: bool) -> Self
Enable or disable SIMD prefiltering.
Prefiltering uses SIMD (memchr/Teddy) to quickly scan for literal substrings before running the full regex engine. This provides significant speedup for:
- Large inputs (>1KB)
- Sparse matches (literal appears rarely)
However, prefiltering adds overhead for:
- Small inputs (<1KB) - setup cost exceeds benefit
- Dense matches - prefilter doesn’t skip much work
Default: disabled (false) - enable explicitly for large input workloads
§Example
use regexr::Regex;
// Enable prefiltering for large input workloads
let re = Regex::builder()
.pattern(r"NEEDLE")
.prefilter(true)
.build()
.unwrap();
// Good for: searching 1MB+ files, log processing, large text analysis
// Not good for: small strings in tight loopsTrait Implementations§
Source§impl Clone for RegexBuilder
impl Clone for RegexBuilder
Source§fn clone(&self) -> RegexBuilder
fn clone(&self) -> RegexBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more