// 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)\)\s+references\s+(?:\[.+?\](?:\.\[.+?\])*)\s+\((\[(.+?)\](,\[(.+?)\])*)\)\s+on\s+").unwrap();
let string = "Alter table [xxx].[sRISRESPPol] add Constraint [FK_cUcZnak_sRISRESPPol] foreign key([IdUcZnak],[IfUcZnak],[huhu]) references [dbo].[dbo].[cUcZnak] ([xx],[Id],[FirstId]) on update no action on delete no action
var regexFK = /\\]\\s+?foreign\\s+?key\\((\\[(.+?)\\](,\\[(.+?)\\])*)\\)\\s+?references\\s+?\\[/g;
var regexPrimaryTable = /\\)\\s+references\\s+(?:\\[.+?\\]\\.)*\\[(.+?)\\]\\s+\\(/g;
foreignTable ^Alter\\s+?table\\s+?(?:\\[.+?]+?\\]\\.)*\\[(.+?)\\]\\s+?add\\s+?Constraint\\s+?\\[
PK \\)\\s+references\\s+(?:\\[.+?\\](?:\\.\\[.+?\\])*)\\s+\\((\\[(.+?)\\](,\\[(.+?)\\])*)\\)\\s+on\\s+
M1 112-173 ) references [dbo].[dbo].[cUcZnak] ([xx],[Id],[FirstId]) on
G1 148-167 [xx],[Id],[FirstId]
G2 149-151 xx
G3 157-167 ,[FirstId]
G4 159-166 FirstId";
// 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/