// 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)^(?:from\s+(\w+)(?:\.\w+)?\s+)?import\s+([^\s,.]+)(?:\.\w+)?").unwrap();
let string = "import numpy as np
import pandas as pd
import pkg.mod1, pkg.mod2
from pkg.mod2 import Bar as Qux
from abc.lmn import pqr
from abc.lmn import pqr as xyz
import mod
from mod import s, foo
from mod import *
from pkg.mod3 import *
from mod import s as string, a as alist
";
// 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/