import Foundation
let pattern = ##"(#EXTM3U\s+|#EXTINF:\d+,|(.*\.\w{3,4}).*\s+)"##
let regex = try! NSRegularExpression(pattern: pattern)
let testString = ##"""
#EXTM3U
#EXTINF:419,Alice in Chains - Rotten Apple
http://192.168.101.22:80/movies/9975.mkv
#EXTINF:260,Alice in Chains - Nutshell
http://192.168.101.22:80/movies/1254.mkv
#EXTINF:255,Alice in Chains - I Stay Away
http://192.168.101.22:80/movies/1254.mkv
#EXTINF:256,Alice in Chains - No Excuses
Alice in Chains_Jar of Flies_04_No Excuses.mp3
#EXTINF:157,Alice in Chains - Whale And Wasp
Alice in Chains_Jar of Flies_05_Whale And Wasp.mp3
#EXTINF:263,Alice in Chains - Don't Follow
Alice in Chains_Jar of Flies_06_Don't Follow.mp3
#EXTINF:245,Alice in Chains - Swing On This
Alice in Chains_Jar of Flies_07_Swing On This.mp3
"""##
let stringRange = NSRange(location: 0, length: testString.utf16.count)
let substitutionString = #""#
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