// 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)\b(.*?])\s(__declspec.+?\)\))(.*?;)").unwrap();
let string = "#if defined (_MSC_VER) && !defined(__clang__)
double pU0[3*4*K_MAX_STACK] __declspec(align(64));
#else
double pU0[3*4*K_MAX_STACK] __attribute__ ((aligned (64)));
#endif
#if defined (_MSC_VER) && !defined(__clang__)
double CC[16] __declspec(align(64)) = {0};
#else
double CC[16] __attribute__ ((aligned (64))) = {0};
#endif
#if defined (_MSC_VER) && !defined(__clang__)
double pU[3*4*K_MAX_STACK] __declspec(align(64));
#else
double pU[3*4*K_MAX_STACK] __attribute__ ((aligned (64)));
#endif";
let substitution = "$2 $1$3";
// result will be a String with the substituted value
let result = regex.replace_all(string, substitution);
println!("{}", result);
}
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/