pub fn match_regex<'a, 'b>(line: &'a str, regex: &'b Regex) -> Option<&'a str> {
    match regex.captures(line) {
        Some(caps) => match caps.get(1) {
            Some(mat) => Some(&line[(mat.start()..mat.end())]),
            None => match caps.get(0) {
                Some(mat) => Some(&line[(mat.start()..mat.end())]),
                None => None,
            },
        },
        None => None,
    }
}
/// Returns the first match of the regular expression within the given line, if any.
///
/// If the regular expression includes capture groups, returns the first capture group's match.
/// Otherwise, returns the overall match.
///
/// # Examples
///
/// ```
/// let first_word = regex::Regex::new(r"\w+").unwrap();
///
/// let second_word = regex::Regex::new(r"\w+\W+(\w+)").unwrap();
///
/// let third_word = regex::Regex::new(r"(?:\w+\W+){2}(\w+)").unwrap();
///
/// assert_eq!("Bishop", groupby::match_regex("Bishop takes queen", &first_word).unwrap());
/// assert_eq!("takes",  groupby::match_regex("Bishop takes queen", &second_word).unwrap());
/// assert_eq!("queen",  groupby::match_regex("Bishop takes queen", &third_word).unwrap());
/// ```
Returns the first match of the regular expression within the given line, if any.
If the regular expression includes capture groups, returns the first capture group's match.
Otherwise, returns the overall match.
Returns the first match of the regular expression within the given line if any . If the regular expression includes capture groups returns the first capture group ' s match . Otherwise returns the overall match .
pub fn match_regex<'a, 'b>(line: &'a str, regex: &'b Regex) -> Option<&'a str> {
    match regex.captures(line) {
        Some(caps) => match caps.get(1) {
            Some(mat) => Some(&line[(mat.start()..mat.end())]),
            None => match caps.get(0) {
                Some(mat) => Some(&line[(mat.start()..mat.end())]),
                None => None,
            },
        },
        None => None,
    }
}
pub fn match_regex < ' a , ' b > ( line : & ' a str , regex : & ' b Regex ) -> Option < & ' a str > { match regex . captures ( line ) { Some ( caps ) => match caps . get ( 1 ) { Some ( mat ) => Some ( & line [ ( mat . start ( ) .. mat . end ( ) ) ] ) , None => match caps . get ( 0 ) { Some ( mat ) => Some ( & line [ ( mat . start ( ) .. mat . end ( ) ) ] ) , None => None , } , } , None => None , } }
Returns the first match of the regular expression within the given line, if any.
Returns the first match of the regular expression within the given line if any .
line
&'a str
regex
&'b Regex
line
&'a str
regex
&'b Regex
examples






assert_eq!("Bishop", groupby::match_regex("Bishop takes queen", &first_word).unwrap());
assert_eq!("takes",  groupby::match_regex("Bishop takes queen", &second_word).unwrap());
assert_eq!("queen",  groupby::match_regex("Bishop takes queen", &third_word).unwrap());
```
assert_eq! ( " Bishop " groupby :: match_regex ( " Bishop takes queen " &first_word ) . unwrap () ) ; assert_eq! ( " takes " groupby :: match_regex ( " Bishop takes queen " &second_word ) . unwrap () ) ; assert_eq! ( " queen " groupby :: match_regex ( " Bishop takes queen " &third_word ) . unwrap () ) ; ` ` `