// include the latest version of the regex crate in your Cargo.toml
extern crate regex;
use regex::Regex;
fn main() {
let regex = Regex::new(r"(?m)^.{0,1}(陪我一起)?听?你?(再|快|先)?能?(给我)?唱?(啊|一?个|吧|出来|一?首)?歌?(给我听|来听听)?(吧|啊|哇|呗|呀)?((好(么|嘛|吗))|好不好|小万|亲爱的|这么难)?.{0,1}$").unwrap();
let string = "你先唱给我听好吗
快唱啊
快唱啊你
你唱吧
你唱一个
唱一首吧亲爱的
再唱一首
你快唱吧
你能唱出来吗
唱出来
唱一个给我听呗好不好
快唱
唱
唱吧
你唱啊
唱一个嘛
唱一个啊
来听你唱歌
再给我唱一首呗
唱歌小万
你唱首歌给我听呗
陪我一起唱歌好吗
听你唱歌这么难
唱首歌来听听
你唱歌好好听啊再给我唱一首呗
我现在就很不开心你唱首歌给我听呗
会不会唱歌,唱首歌来听听";
// result will be an iterator over tuples containing the start and end indices for each match in the string
let result = regex.captures_iter(string);
for mat in result {
println!("{:?}", mat);
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Rust, please visit: https://docs.rs/regex/latest/regex/