// 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)(\(\s?function+.formula.*\{\s?)([\w|\.]+\s?=[^\}]*)(\s?\}\s?\)\s?\(\s?\)\s?;)").unwrap();
let string = " (function Formula(x){ ListaOP.FormaPActiva.RemanenteACancelar = ListaOP.OPActiva.TotalesCliente.Total - ListaOP.OPActiva.MontoAcumuladoFormasPago; })(variableX);
(function Formula() { ListaOP.FormaPActiva.ImporteACancelar = ListaOP.FormaPActiva.RemanenteACancelar; })();
(function formula(){ a=b; })();
if (!v.Parametros.AfectarGastoEnvioRecargoFinanciero && ListaOP.OPActiva.MontoCanceladoContado < v.GastoEnvio + v.GastoEnvioImpuestoCliente) {
(function formula() { ListaOP.FormaPActiva.RemanenteACancelar = ListaOP.FormaPActiva.RemanenteACancelar - v.GastoEnvio - v.GastoEnvioImpuestoCliente; })();
}
var c = function(){
};
(function Formula() { ListaOP.FormaPActiva.ImporteFinanciamientoTotal = ListaOP.FormaPActiva.RemanenteACancelar * (ListaOP.FormaPActiva.CoeficienteFinanciacion - 1); })();
(function Formula() { ListaOP.FormaPActiva.ImporteACancelar = ListaOP.FormaPActiva.ImporteACancelar + ListaOP.FormaPActiva.ImporteFinanciamientoTotal; })();
(function Formula(x) { ListaOP.FormaPActiva.RemanenteACancelar = ListaOP.FormaPActiva.ImporteACancelar; })(10);";
let substitution = "Calcular('$2'); ";
// 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/