import Foundation
let pattern = #"^.*?\+?0*610?(\d{3})(\d{3})(\d{4})(?!\d).*$"#
let regex = try! NSRegularExpression(pattern: pattern, options: .anchorsMatchLines)
let testString = #"""
xgsh6101231231234vvajxxgsh6101231231234vvajx
xgsh06101231231234vvajx
xgsh000006101231231234vvajx
+6101231231234
xgsh61012312312345vvajx
xgsh5101231231234vvajx
xgsh00000101231231234vvajx
xgsh6143545626455345601231231234vvajx
"""#
let stringRange = NSRange(location: 0, length: testString.utf16.count)
let substitutionString = #"+61 (0) $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