import Foundation
let pattern = #"SSR.(....)(.BE.)(\w+)(-1)(\w+)(\/)(\w+).*"#
let regex = try! NSRegularExpression(pattern: pattern, options: .anchorsMatchLines)
let testString = #"""
SSR BAGW BE HK1DUBEXT0304H13OCT-1TIMBRELL/TEGAELAMISS.1P/AUTH 23KG
SSR BAGA BE HK1DUBLON0301H13NOV-1TIMBRELL/TEGAELAMISS.1P/AUTH 23KG
SSR DOCS BE HK1DUBEXT0204H13DEC-1TIMBRELL/TEGAELAMISS
SSR PETC BE HK1LONEXT0334H13JAN-1TIMBRELL/TEGAELAMISS
SSR WCHR BE HK1DUBEXT0204H13DEC-1TIMBRELL/TEGAELAMISS
SSR BAGW BE HK1DUBLON0301H13NOV-1TIMBRELL/TEGAELAMISS.1P/AUTH 23KG
BE7351 H 08NOV18MANMXP HK4/11251440
BE2108R/VS8508Y 11NOV18LHREDI HK10/18202000
A97351 H 08NOV18MANMXP HK4/11251440
"""#
let stringRange = NSRange(location: 0, length: testString.utf16.count)
let substitutionString = #"\1-\5-\7"#
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