import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(\\w+\\s+)(\\w+\\?*\\s+)(\\w+)\\s+(\\{.+\\})";
final String string = "public Guid DellUploadItemID { get; set; }\n"
+ "public Guid UploadID { get; set; }\n"
+ "public string DellPurchaseID { get; set; }\n"
+ "public string PoNum { get; set; }\n"
+ "public string OrderNum { get; set; }\n"
+ "public string OrderType { get; set; }\n"
+ "public string InvoiceNum { get; set; }\n"
+ "public string PaymentDescription { get; set; }\n"
+ "public DateTime? OrderDate { get; set; }\n"
+ "public DateTime? ShippedDate { get; set; }\n"
+ "public DateTime? InvoiceDate { get; set; }\n"
+ "public decimal ReportLineTotal { get; set; }\n"
+ "public string ServiceTag { get; set; }\n"
+ "public string Category { get; set; }\n"
+ "public string SubCategory { get; set; }\n"
+ "public string Item { get; set; }\n"
+ "public string ItemLongName { get; set; }\n"
+ "public DateTime? WarrantyEndDate { get; set; }\n"
+ "public string ShipFirstName { get; set; }\n"
+ "public string ShipLastName { get; set; }\n"
+ "public string ShipToCompany { get; set; }\n"
+ "public string ShipAddress1 { get; set; }\n"
+ "public string ShipAddress2 { get; set; }\n"
+ "public string ShipCity { get; set; }\n"
+ "public string ShipState { get; set; }\n"
+ "public string ShipZip { get; set; }\n"
+ "public string ShipMethod { get; set; }\n"
+ "public string CarrierName { get; set; }\n"
+ "public string WaybillNumber { get; set; }\n"
+ "public string ExpressServiceCode { get; set; }\n"
+ "public string MACAddress { get; set; }\n"
+ "public string MACAddress2 { get; set; }";
final String subst = "\\3 = d.\\3,";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE | Pattern.CASE_INSENSITIVE);
final Matcher matcher = pattern.matcher(string);
// The substituted value will be contained in the result variable
final String result = matcher.replaceAll(subst);
System.out.println("Substitution result: " + 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 Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html