// 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"(?i).*(?:\d(?:\.\d+)?\s*x\s*)?\K(?<!\d)\d+(?:\.\d+)?(?:k?g|m?l)\b|(?<!\d)\d+(?:\.\d+)?(?:k?g|m?l)(?=\s*x\s*\d)").unwrap();
let string = "product brand A 1237ml Bundle of 6
product milk choc370ML
brand milk Vanilla Flavor 850g
One 2400g, For 0-6 Month-Old Infants
a+...two...6-12months...11.2kg...milk
a+...two...11.2kg 6-12months ..milk
Product 200g (10x2g)
[200g] Product
Product A brand(300g)
Product 200g (20g x 10)";
// 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/