import Foundation
let pattern = #"(..)(..)(..)(..)(..)(..)(..)(..)(..)(..)(..)(..)(..)(..)(..)(..)"#
let regex = try! NSRegularExpression(pattern: pattern, options: .anchorsMatchLines)
let testString = #"000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F"#
let stringRange = NSRange(location: 0, length: testString.utf16.count)
let substitutionString = #"\t0x$1,0x$2,0x$3,0x$4,0x$5,0x$6,0x$7,0x$8,0x$9,0x$10,0x$11,0x$12,0x$13,0x$14,0x$15,0x$16\n"#
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