// 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"(?mi)Samsung(?=.*?Galaxy S)").unwrap();
let string = "$data =
Array
(
[0] => Array
(
[name] => Samsung GT-N7100 Galaxy Note II 16GB
)
[1] => Array
(
[name] => Samsung GT-i9100 Galaxy S II
)
[2] => Array
(
[name] => Samsung GT-i9300 Galaxy S III 16GB
)
[3] => Array
(
[name] => Apple iPhone 5 16GB
)
[4] => Array
(
[name] => Samsung GT-P5110 Galaxy S 4 10.1 16GB
)
[5] => Array
(
[name] => Samsung UE46ES6715
)
[6] => Array
(
[name] => Samsung 830 Series MZ-7PC128 128GB
)
[7] => Array
(
[name] => Samsung GT-N8000 Galaxy Note 10.1 16GB
)
[8] => Array
(
[name] => Samsung 830 Series MZ-7PC256 256GB
)
[9] => Array
(
[name] => Samsung UE46ES6715
)
[10] => Array
(
[name] => Samsung GT-2423 Galaxy Tab 4 10.1 16GB
)";
// 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/