import Foundation
let pattern = #"(\d+)-(\d+)\s+(.*)"#
let regex = try! NSRegularExpression(pattern: pattern, options: [.anchorsMatchLines, .caseInsensitive])
let testString = #"""
3-01 Wait for It.mp4
3-02 We're Not from Here.mp4
3-03 Third Wheel.mp4
3-04 Little Boys.mp4
3-05 How I Met Everyone Else.mp4
3-06 I'm Not That Guy.mp4
3-07 Dowisetrepla.mp4
3-08 Spoiler Alert.mp4
3-09 Slapsgiving.mp4
3-10 The Yips.mp4
3-11 The Platinum Rule.mp4
3-12 No Tomorrow.mp4
3-13 Ten Sessions.mp4
3-14 The Bracket.mp4
3-15 The Chain of Screaming.mp4
3-16 Sandcastles in the Sand.mp4
3-17 The Goat.mp4
3-18 Rebound Bro.mp4
"""#
let stringRange = NSRange(location: 0, length: testString.utf16.count)
let substitutionString = #"How I Met Your Mother S$1E$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