import Foundation
let pattern = #"public [A-Za-z\?]* ([A-Za-z0-9]*) .*"#
let regex = try! NSRegularExpression(pattern: pattern, options: [.anchorsMatchLines, .caseInsensitive])
let testString = #"""
public string AddressLine1 { get; set; }
public string AddressLine2 { get; set; }
public string AddressLine3 { get; set; }
public string AddressLine4 { get; set; }
public string AddressLine5 { get; set; }
public string AddressLine6 { get; set; }
public DateTime? Dob { get; set; }
public string EmailAddress { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string PostCode { get; set; }
public string PrimaryPhoneNo { get; set; }
public string Title { get; set; }
"""#
let stringRange = NSRange(location: 0, length: testString.utf16.count)
let substitutionString = #"$1 = customerDetails.$1,"#
let result = regex.stringByReplacingMatches(in: testString, range: stringRange, withTemplate: substitutionString)
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 Swift 5.2, please visit: https://developer.apple.com/documentation/foundation/nsregularexpression