pub struct Regex { /* private fields */ }Expand description
Main Regex struct
Holds a regular expression
Implementations§
Source§impl Regex
impl Regex
Sourcepub fn compile(src: &str) -> Result<Self, RegexError>
pub fn compile(src: &str) -> Result<Self, RegexError>
Compile the given string into a Regex
Returns error if the regex is invalid and fails to compile
§Errors
If the regex fails to compile, the error variant contains a message explaining the issue
Examples found in repository?
examples/example.rs (line 14)
3fn main() {
4 /* let rule = "^(abc|cba)$"; */
5 /* let r = Regex::compile(rule).unwrap(); */
6
7 /* println!("{rule} : {r}"); */
8
9 /* for st in ["abc", "cba", ".abc", ".cba", ".cga"] { */
10 /* println!("{st} => {}", */
11 /* r.test(st)); */
12 /* } */
13
14 let regex = Regex::compile(".*b").unwrap();
15 for m in regex.find_matches("aaaaaabaaaaaab") {
16 println!("{m:#?}");
17 }
18}Sourcepub fn find_matches<'a>(&'a self, src: &'a str) -> RegexMatcher<'a> ⓘ
pub fn find_matches<'a>(&'a self, src: &'a str) -> RegexMatcher<'a> ⓘ
Examples found in repository?
examples/example.rs (line 15)
3fn main() {
4 /* let rule = "^(abc|cba)$"; */
5 /* let r = Regex::compile(rule).unwrap(); */
6
7 /* println!("{rule} : {r}"); */
8
9 /* for st in ["abc", "cba", ".abc", ".cba", ".cga"] { */
10 /* println!("{st} => {}", */
11 /* r.test(st)); */
12 /* } */
13
14 let regex = Regex::compile(".*b").unwrap();
15 for m in regex.find_matches("aaaaaabaaaaaab") {
16 println!("{m:#?}");
17 }
18}Sourcepub fn find_matches_with_conf<'a>(
&'a self,
src: &'a str,
conf: RegexConf,
) -> RegexMatcher<'a> ⓘ
pub fn find_matches_with_conf<'a>( &'a self, src: &'a str, conf: RegexConf, ) -> RegexMatcher<'a> ⓘ
Just like find_matches, but uses a different configuration
Trait Implementations§
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
Mutably borrows from an owned value. Read more