import Foundation
let pattern = #"(.+)(\s)(=)(\s)(.*)(,)(.*)(,)(.*)"#
let regex = try! NSRegularExpression(pattern: pattern, options: .anchorsMatchLines)
let testString = #"""
haha = 1,5,QQQ
hah4a = 4,5,Qss
h1aha = 3,5,QDa
haasdha = 2,5,QVV
ha = 1,7,QQw
h11aha = 1,2,Qfd
hah00a = 1,1,gfdgQ
hahaazzza = 3,5,oooo
"""#
let stringRange = NSRange(location: 0, length: testString.utf16.count)
let substitutionString = #"$9$8$7$8$5$8$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