Trait string_patterns::PatternMatch
source · pub trait PatternMatch {
// Required methods
fn pattern_match_result(
&self,
pattern: &str,
case_insensitive: bool
) -> Result<bool, Error>;
fn pattern_match(&self, pattern: &str, case_insensitive: bool) -> bool;
fn pattern_match_ci(&self, pattern: &str) -> bool;
fn pattern_match_cs(&self, pattern: &str) -> bool;
}
Expand description
This library provides a set of traits and extension methods for &str and/or String to facilitate common string manipulations routines that may require multiple steps with the Rust standard library + Regex. Once installed you need not explicitly add regex::* to your project and string types will have many new match, replace, split and extract methods. Most methods imvoling regular expressions have variants ending in result returning the reuslt type with an error from the Regex crate and without, that return false and skips replacements if the regular is invalid. Use the main methods if you have tested your regular expression. There are also variants with a case_insensitive flag and without (_ci and _cs). When used on arrays or vectors of strings each regular expression will only be compiled and checked once, when you need to search within a large set of text records. Complex regular expressions, e.g. with look behind (?<=foo) or look ahead, work best after isolating a sample text snippet via simpler text-matching methods. Always consider the simplest strategy for extracting text, e.g. via to_head_tail(), to_segments(), before resorting to the regex-enabled pattern-prefixed methods. Core regular expression match methods
Required Methods§
sourcefn pattern_match_result(
&self,
pattern: &str,
case_insensitive: bool
) -> Result<bool, Error>
fn pattern_match_result( &self, pattern: &str, case_insensitive: bool ) -> Result<bool, Error>
Apply a regular expression match on the current string If the regex doesn’t compile it will return an error
sourcefn pattern_match(&self, pattern: &str, case_insensitive: bool) -> bool
fn pattern_match(&self, pattern: &str, case_insensitive: bool) -> bool
Apply a regular expression match on the current string with a boolean case_insensitive flag NB: If the regex doesn’t compile it will return false
sourcefn pattern_match_ci(&self, pattern: &str) -> bool
fn pattern_match_ci(&self, pattern: &str) -> bool
Apply a regular expression match on the current string in case-insensitive mode NB: If the regex doesn’t compile it will return false
sourcefn pattern_match_cs(&self, pattern: &str) -> bool
fn pattern_match_cs(&self, pattern: &str) -> bool
Apply a regular expression match on the current string in case-sensitive mode NB: If the regex doesn’t compile it will return false
Implementations on Foreign Types§
source§impl PatternMatch for str
impl PatternMatch for str
Implement regular expression match and replace methods for str and owned String
source§fn pattern_match_result(
&self,
pattern: &str,
case_insensitive: bool
) -> Result<bool, Error>
fn pattern_match_result( &self, pattern: &str, case_insensitive: bool ) -> Result<bool, Error>
Simple regex-compatible match method that will return an optional boolean
- Some(true) means the regex is valid and the string matches
- Some(false) means the regex is valid and the string does not match
- None means the regex is not valid and can this not be evaluated
source§fn pattern_match(&self, pattern: &str, case_insensitive: bool) -> bool
fn pattern_match(&self, pattern: &str, case_insensitive: bool) -> bool
Simple regex-compatible match method that will return false if the pattern does not match the source string or the regex fails
source§fn pattern_match_ci(&self, pattern: &str) -> bool
fn pattern_match_ci(&self, pattern: &str) -> bool
Simple case-insensitive regex-compatible match method that will return false if the pattern does not match the source string or the regex fails
source§fn pattern_match_cs(&self, pattern: &str) -> bool
fn pattern_match_cs(&self, pattern: &str) -> bool
Simple case-sensitive regex-compatible match method that will return false if the pattern does not match the source string or the regex fails
source§impl PatternMatch for [String]
impl PatternMatch for [String]
source§fn pattern_match(&self, pattern: &str, case_insensitive: bool) -> bool
fn pattern_match(&self, pattern: &str, case_insensitive: bool) -> bool
Simple regex-compatible match method that will return false if the pattern does not match the source string or the regex fails
source§fn pattern_match_ci(&self, pattern: &str) -> bool
fn pattern_match_ci(&self, pattern: &str) -> bool
Case-insensitive regex-compatible match method that will return false if the pattern does not match the source string or the regex fails
source§fn pattern_match_cs(&self, pattern: &str) -> bool
fn pattern_match_cs(&self, pattern: &str) -> bool
Case-sensitive regex-compatible match method that will return false if the pattern does not match the source string or the regex fails