mirror of
https://gitee.com/openharmony/third_party_rust_regex
synced 2025-04-14 08:30:18 +00:00

Regex sets permit matching multiple (possibly overlapping) regular expressions in a single scan of the search text. This adds a few new types, with `RegexSet` being the primary one. All matching engines support regex sets, including the lazy DFA. This commit also refactors a lot of the code around handling captures into a central `Search`, which now also includes a set of matches that is used by regex sets to determine which regex has matched. We also merged the `Program` and `Insts` type, which were split up when adding the lazy DFA, but the code seemed more complicated because of it. Closes #156.
20 lines
385 B
Rust
20 lines
385 B
Rust
extern crate regex;
|
|
|
|
use regex::RegexSet;
|
|
|
|
fn main() {
|
|
let res = &[
|
|
"abc",
|
|
"xyzz",
|
|
"^[ga-fh-z]+$",
|
|
];
|
|
let text = "abcggggggggxyz";
|
|
let set = RegexSet::new(res).unwrap();
|
|
println!("{:?}", set);
|
|
let m = set.is_match("abcggggggggxyz");
|
|
println!("match? {:?}", m);
|
|
for mi in set.matches(text) {
|
|
println!("{:?}", mi);
|
|
}
|
|
}
|