import re
regex = re.compile(r"(\w+\s+)(\w+\?*\s+)(\w+)\s+(\{.+\})", flags=re.MULTILINE | re.IGNORECASE)
test_str = ("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; }")
subst = "\\3 = d.\\3,"
result = regex.sub(subst, test_str)
if result:
print(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 Python, please visit: https://docs.python.org/3/library/re.html