Skip to content

Simple example to do overlapping regex matches #1261

Answered by gagbo
gagbo asked this question in Q&A
Discussion options

You must be logged in to vote

Yeah I just figured that out!! Thanks

Final code to mark the answer:

use regex_automata::{
    Anchored, Input, MatchKind,
    hybrid::dfa::{DFA, OverlappingState},
    hybrid::regex::{Cache, Regex},
}; // 0.4.9

const EMAIL_REGEX: &str = r"[a-zA-Z0-9-_.]*[a-zA-Z0-9_](@[a-zA-Z0-9_]+)(\.[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)?[a-zA-Z])(?-u:\b)";
const SHA_REGEX: &str = r"(?-u:\b)[0-9a-fA-F]{7,28}(?-u:\b)";

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
struct Match {
    pattern_id: usize,
    offset_start: usize,
    offset_end: usize,
}

fn main() {
    let haystack = "[email protected]";
    assert_eq!(
        &find_all_matches(haystack),
        &[
            Match {
                pattern_id: 

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
5 replies
@BurntSushi
Comment options

@gagbo
Comment options

Answer selected by gagbo
@BurntSushi
Comment options

@gagbo
Comment options

@BurntSushi
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants