# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"(\w+\s+)(\w+\?*\s+)(\w+)\s+(\{.+\})"
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,"
# You can manually specify the number of replacements by changing the 4th argument
result = re.sub(regex, subst, test_str, 0, re.MULTILINE | re.IGNORECASE)
if result:
print (result)
# Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.
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