pub struct RegexBuilder(/* private fields */);
Expand description
A builder for a Regex
to allow configuring options.
Implementations§
Source§impl RegexBuilder
impl RegexBuilder
Sourcepub fn new(pattern: &str) -> Self
pub fn new(pattern: &str) -> Self
Create a new regex builder with a regex pattern.
If the pattern is invalid, the call to build
will fail later.
Sourcepub fn build(&self) -> Result<Regex>
pub fn build(&self) -> Result<Regex>
Build the Regex
.
Returns an Error
if the pattern could not be parsed.
Sourcepub fn case_insensitive(&mut self, yes: bool) -> &mut Self
pub fn case_insensitive(&mut self, yes: bool) -> &mut Self
Override default case insensitive this is to enable/disable casing via builder instead of a flag within the raw string provided to the regex builder
Default is false
Sourcepub fn multi_line(&mut self, yes: bool) -> &mut Self
pub fn multi_line(&mut self, yes: bool) -> &mut Self
Enable multi-line regex
Sourcepub fn ignore_whitespace(&mut self, yes: bool) -> &mut Self
pub fn ignore_whitespace(&mut self, yes: bool) -> &mut Self
Allow ignore whitespace
Sourcepub fn dot_matches_new_line(&mut self, yes: bool) -> &mut Self
pub fn dot_matches_new_line(&mut self, yes: bool) -> &mut Self
Enable or disable the “dot matches any character” flag.
When this is enabled, .
will match any character. When it’s disabled, then .
will match any character
except for a new line character.
Sourcepub fn verbose_mode(&mut self, yes: bool) -> &mut Self
pub fn verbose_mode(&mut self, yes: bool) -> &mut Self
Enable verbose mode in the regular expression.
The same as ignore_whitespace
When enabled, verbose mode permits insigificant whitespace in many
places in the regular expression, as well as comments. Comments are
started using #
and continue until the end of the line.
By default, this is disabled. It may be selectively enabled in the
regular expression by using the x
flag regardless of this setting.
Sourcepub fn unicode_mode(&mut self, yes: bool) -> &mut Self
pub fn unicode_mode(&mut self, yes: bool) -> &mut Self
Enable or disable the Unicode flag (u
) by default.
By default this is enabled. It may alternatively be selectively
disabled in the regular expression itself via the u
flag.
Note that unless “allow invalid UTF-8” is enabled (it’s disabled by default), a regular expression will fail to parse if Unicode mode is disabled and a sub-expression could possibly match invalid UTF-8.
WARNING: Unicode mode can greatly increase the size of the compiled
DFA, which can noticeably impact both memory usage and compilation
time. This is especially noticeable if your regex contains character
classes like \w
that are impacted by whether Unicode is enabled or
not. If Unicode is not necessary, you are encouraged to disable it.
Sourcepub fn backtrack_limit(&mut self, limit: usize) -> &mut Self
pub fn backtrack_limit(&mut self, limit: usize) -> &mut Self
Limit for how many times backtracking should be attempted for fancy regexes (where
backtracking is used). If this limit is exceeded, execution returns an error with
Error::BacktrackLimitExceeded
.
This is for preventing a regex with catastrophic backtracking to run for too long.
Default is 1_000_000
(1 million).
Sourcepub fn delegate_size_limit(&mut self, limit: usize) -> &mut Self
pub fn delegate_size_limit(&mut self, limit: usize) -> &mut Self
Set the approximate size limit of the compiled regular expression.
This option is forwarded from the wrapped regex
crate. Note that depending on the used
regex features there may be multiple delegated sub-regexes fed to the regex
crate. As
such the actual limit is closer to <number of delegated regexes> * delegate_size_limit
.
Sourcepub fn delegate_dfa_size_limit(&mut self, limit: usize) -> &mut Self
pub fn delegate_dfa_size_limit(&mut self, limit: usize) -> &mut Self
Set the approximate size of the cache used by the DFA.
This option is forwarded from the wrapped regex
crate. Note that depending on the used
regex features there may be multiple delegated sub-regexes fed to the regex
crate. As
such the actual limit is closer to <number of delegated regexes> * delegate_dfa_size_limit
.