// 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)^(public (?:(?!{|event|delegate)[^=;])*);").unwrap();
let string = "Regex: ^public ((?!({))(?!=).)*;
//MATCHES CORRECTLY
public string Country;
public string EmailAddress;
public string FirstName;
public string LastName;
public string PhoneNumber;
public string PostalCode;
public string State;
public List<Object> Example;
//MATCHES BUT SHOULDNT
public event GetUserListCompletedEventHandler GetUserListCompleted;
public delegate void GetUserListCompletedEventHandler(object sender, GetUserListCompletedEventArgs e);
//DOES NOT MATCH CORRECTLY
throw new Exception(\"In order to get the public date for blah blah blah\");
public List<Order> orderDetails = new List<Order>();
public string CustomerName { get; set; }
public string BillingAddress1 { get; set; }
public string BillingAddress2 { get; set; }";
let substitution = "$1 { get; set; }";
// 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/