All non overlapping matches, plus the group count for output shaping. */
(pattern: &str, text: &str)
| 63 | |
| 64 | /* All non overlapping matches, plus the group count for output shaping. */ |
| 65 | pub fn find_all(pattern: &str, text: &str) -> Result<(Vec<Found>, usize), ReError> { |
| 66 | let re = Regex::compile(pattern)?; |
| 67 | let chars: Vec<char> = text.chars().collect(); |
| 68 | let m = Matcher::new(&chars, re.prog.flags); |
| 69 | let mut out = Vec::new(); |
| 70 | let mut start = 0; |
| 71 | while start <= chars.len() { |
| 72 | match m.search_from(&re.prog.root, re.prog.group_count, start) { |
| 73 | Some(c) => { |
| 74 | let (s, e) = c[0].unwrap(); |
| 75 | out.push(build(&chars, &c, re.prog.group_count)); |
| 76 | start = if e > s { e } else { e + 1 }; // step past an empty match |
| 77 | } |
| 78 | None => { |
| 79 | if m.exceeded() { return Err(too_complex()); } |
| 80 | break; |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | Ok((out, re.prog.group_count)) |
| 85 | } |
| 86 | |
| 87 | /* Replace every match, expanding backreferences in the template. */ |
| 88 | pub fn sub(pattern: &str, repl: &str, text: &str) -> Result<String, ReError> { |
no test coverage detected