// 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)modelBuilder\.Entity<(?'type'\w+)>\(builder =>\n\s*\{(?'builder'[\w\W]+?)\}\);").unwrap();
let string = "modelBuilder.Entity<Foobar>(builder =>
{
builder.HasKey(e => e.Id).HasName(\"PRIMARY\");
builder
.ToTable(\"foobar\")
.UseCollation(\"utf8mb4_0900_ai_ci\");
builder.HasIndex(e => e.A, \"A\").IsUnique();
builder.Property(e => e.D).HasColumnType(\"datetime\");
builder.Property(e => e.E)
.HasMaxLength(255)
.UseCollation(\"utf8mb4_unicode_ci\");
builder.Property(e => e.N)
.HasMaxLength(255)
.UseCollation(\"utf8mb4_unicode_ci\");
builder.HasOne(d => d.ANav).WithOne(p => p.BNav)
.HasForeignKey<Foobar>(d => d.Leerling)
.HasConstraintName(\"Foobar_fk\");
});";
let substitution = "public class $1Mapping : IEntityTypeConfiguration<$1>\\n{\\n public void Configure(EntityTypeBuilder<$1> builder)\\n {\\n$2\\n}}";
// 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/