pub struct Regex { /* private fields */ }Expand description
An abstraction for regex patterns.
- Allows swapping out the regex implementation because it’s only in this module.
- Makes regexes serializable and deserializable using just the pattern string.
- Lazily compiles regexes on first use to improve initialization time.
Implementations§
Source§impl Regex
impl Regex
Sourcepub fn new(regex_str: String) -> Self
pub fn new(regex_str: String) -> Self
Create a new regex from the pattern string.
Note that the regex compilation happens on first use, which is why this method does not return a result.
Sourcepub fn try_compile(
regex_str: &str,
) -> Option<Box<dyn Error + Send + Sync + 'static>>
pub fn try_compile( regex_str: &str, ) -> Option<Box<dyn Error + Send + Sync + 'static>>
Check whether the pattern compiles as a valid regex or not.
Sourcepub fn is_match<'t>(
&self,
text: &'t str,
ignore_errors: bool,
) -> Result<bool, ParseSyntaxError>
pub fn is_match<'t>( &self, text: &'t str, ignore_errors: bool, ) -> Result<bool, ParseSyntaxError>
Check if the regex matches the given text.
Sourcepub fn search(
&self,
text: &str,
begin: usize,
end: usize,
region: Option<&mut Region>,
ignore_errors: bool,
) -> Result<bool, ParseSyntaxError>
pub fn search( &self, text: &str, begin: usize, end: usize, region: Option<&mut Region>, ignore_errors: bool, ) -> Result<bool, ParseSyntaxError>
Search for the pattern in the given text from begin/end positions.
If a region is passed, it is used for storing match group positions. The argument allows
the Region to be reused between searches, which makes a significant performance
difference.
Sourcepub fn is_match_failible<'t>(&self, text: &'t str) -> Result<bool, &str>
pub fn is_match_failible<'t>(&self, text: &'t str) -> Result<bool, &str>
Check if the regex matches the given text.
In order to be called repetitively when in error, the error message is returned as a &str without allocation
Sourcepub fn search_failible(
&self,
text: &str,
begin: usize,
end: usize,
region: Option<&mut Region>,
) -> Result<bool, &str>
pub fn search_failible( &self, text: &str, begin: usize, end: usize, region: Option<&mut Region>, ) -> Result<bool, &str>
Search for the pattern in the given text from begin/end positions.
If a region is passed, it is used for storing match group positions. The argument allows
the Region to be reused between searches, which makes a significant performance
difference.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Regex
impl<'de> Deserialize<'de> for Regex
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
impl Eq for Regex
Auto Trait Implementations§
impl !Freeze for Regex
impl RefUnwindSafe for Regex
impl Send for Regex
impl Sync for Regex
impl Unpin for Regex
impl UnwindSafe for Regex
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.