import Foundation
let pattern = #"(\S)(,)(\S)"#
let regex = try! NSRegularExpression(pattern: pattern, options: .anchorsMatchLines)
let testString = #"""
SELECT tbl_Generic_Tool.Generic_Type_ID, tbl_ref_Generic_Type.Generic_Type,
tbl_Hex.ODD_Micap,tbl_Hex.Hex_ID,tbl_Hex.Hex_No ,Min(tbl_ref_Phase.Phase) AS FirstOfPhase,tbl_ref_Building.Building_Abbrev,tbl_ref_Status_Equipment.Status_Equipment
GROUP BY
tbl_Generic_Tool.Generic_Type_ID,tbl_ref_Generic_Type.Generic_Type,tbl_Hex.ODD_Micap,tbl_Hex.Hex_ID,tbl_Hex.Hex_No,tbl_ref_Building.Building_Abbrev,tbl_Hex.Status_Equipment_ID,tbl_ref_Status_Equipment.Status_Equipment
HAVING
(((tbl_Hex.ODD_Micap) < CONVERT(DATE,GETDATE()))
AND ((tbl_Hex.Status_Equipment_ID) = 2)))¦ AS H
LEFT JOIN tbl_POC_Assigned ON H.Hex_ID = tbl_POC_Assigned.Hex_ID
GROUP BY
H.Generic_Type
,H.Building_Abbrev
,H.ODD_Micap
,H.Hex_ID
,H.Hex_No
,H.Status_Equipment
"""#
let stringRange = NSRange(location: 0, length: testString.utf16.count)
let substitutionString = #"\1\2 \3"#
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