import Foundation
let pattern = #"(\-?\d+(\.\d+)?),\s*(\-?\d+(\.\d+)?)"#
let regex = try! NSRegularExpression(pattern: pattern)
let testString = #"1.3626104100298,44.0313777738606,0 -121.3627743244628,44.03123252081081,0 -121.3627794325398,44.03122812311533,0 -121.3627843389654,44.03122393122449,0 -121.3627892667884,44.0312197526747,0 -121.3627942147613,44.0312155874754,0 -121.3627991841185,44.03121143471726,0 -121.3628041748603,44.03120729440029,0 -121.3628091845174,44.03120316834296,0 -121.3628142168063,44.03119905471752,0 -121.3628192704925,44.0311949544332,0 -121.3628243430812,44.03119086750853,0 -121.3628294370801,44.03118679482493,0 -121.362834551216,44.0311827345917,0 -121.3628396867492,44.03117868769964,0 -121.3628448411978,44.03117465506718,0 -121.3628500170308,44.03117063487584,0 -121.3621653794692,44.03071984342947,0 -121.3619768731163,44.03100429635388,0 -121.3626104100298,44.0313777738606,0"#
let stringRange = NSRange(location: 0, length: testString.utf16.count)
if let firstMatch = regex.firstMatch(in: testString, range: stringRange) {
let result: [String] = (1 ..< firstMatch.numberOfRanges).map { (testString as NSString).substring(with: firstMatch.range(at: $0)) }
print(result)
} else {
print("No matches were found.")
}
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