fancy-regex crate multiple matches

前端 未结 1 1741
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-28 23:57

I\'m using the fancy-regex crate since I need lookaheads in my Regex but it seems like it\'s not getting all of the matches in a string like I can with the regex crate which fan

相关标签:
1条回答
  • 2021-01-29 00:55

    Note that your fancy_regex code looks for two captures in a single match, which is doomed to fail since your expression only contains one capture group. What you want (and what you're doing with regex) is a way to iterate through the matches, but it looks like fancy_regex does not have an easy way to do it. So you will need to do it manually:

    let mut start = 0;
    while let Some (m) = re.captures_from_pos (values, start).unwrap() {
       println!("{:?}", m.get (1).unwrap());
       start = m.get (0).unwrap().start() + 1; // Or you can use `end` to avoid overlapping matches
    }
    
    0 讨论(0)
提交回复
热议问题