import Foundation
let pattern = #"^(http://|https://|http://www\.|https://www\.|www\.)?(www\.(twanda))?(([\w\-]+)?\.?(twanda|))(\.ch|\.com)(:\d+)?/.+$"#
let regex = try! NSRegularExpression(pattern: pattern, options: [.anchorsMatchLines, .caseInsensitive])
let testString = #"""
www.twanda.ch/store/apps/details?id=com.skgames.trafficracer%22
www.twanda.ch:8069/store/apps/details?id=com.skgames.trafficracer%22
twanda.ch/store/apps/details?id=com.skgames.trafficracer%22
twanda.ch:8069/store/apps/details?id=com.skgames.trafficracer%22
http://twanda.ch/store/apps/details?id=com.skgames.trafficracer%22
https://twanda.ch:8069/store/apps/details?id=com.skgames.trafficracer%22
http://www.twanda.ch/store/apps/details?id=com.skgames.trafficracer%22
http://www.twanda.ch:8069/store/apps/details?id=com.skgames.trafficracer%22
https://www.twanda.ch/store/apps/details?id=com.skgames.trafficracer%22
https://www.twanda.ch:8069/store/apps/details?id=com.skgames.trafficracer%22
flohmarkt-zug.twanda.ch/store/apps/details?id=com.skgames.trafficracer%22
flohmarkt-zug.twanda.ch:8069/store/apps/details?id=com.skgames.trafficracer%22
http://flohmarkt-zug.twanda.ch/store/apps/details?id=com.skgames.trafficracer%22
http://flohmarkt-zug.twanda.ch:8069/store/apps/details?id=com.skgames.trafficracer%22
https://flohmarkt-zug.twanda.ch/store/apps/details?id=com.skgames.trafficracer%22
https://flohmarkt-zug.twanda.ch:8069/store/apps/details?id=com.skgames.trafficracer%22
www.flohmarkt-zug.ch/store/apps/details?id=com.skgames.trafficracer%22
www.flohmarkt-zug.ch:8069/store/apps/details?id=com.skgames.trafficracer%22
flohmarkt-zug.ch/store/apps/details?id=com.skgames.trafficracer%22
flohmarkt-zug.ch:8069/store/apps/details?id=com.skgames.trafficracer%22
http://www.flohmarkt-zug.ch/store/apps/details?id=com.skgames.trafficracer%22
http://www.flohmarkt-zug.ch:8069/store/apps/details?id=com.skgames.trafficracer%22
https://www.flohmarkt-zug.ch/store/apps/details?id=com.skgames.trafficracer%22
https://www.flohmarkt-zug.ch:8069/store/apps/details?id=com.skgames.trafficracer%22
www.twanda.com/store/apps/details?id=com.skgames.trafficracer%22
www.twanda.com:8069/store/apps/details?id=com.skgames.trafficracer%22
twanda.com/store/apps/details?id=com.skgames.trafficracer%22
twanda.com:8069/store/apps/details?id=com.skgames.trafficracer%22
http://www.twanda.com/store/apps/details?id=com.skgames.trafficracer%22
http://www.twanda.com:8069/store/apps/details?id=com.skgames.trafficracer%22
https://www.twanda.com/store/apps/details?id=com.skgames.trafficracer%22
https://www.twanda.com:8069/store/apps/details?id=com.skgames.trafficracer%22
flohmarkt-zug.twanda.com/store/apps/details?id=com.skgames.trafficracer%22
flohmarkt-zug.twanda.com:8069/store/apps/details?id=com.skgames.trafficracer%22
http://flohmarkt-zug.twanda.com/store/apps/details?id=com.skgames.trafficracer%22
http://flohmarkt-zug.twanda.com:8069/store/apps/details?id=com.skgames.trafficracer%22
https://flohmarkt-zug.twanda.com/store/apps/details?id=com.skgames.trafficracer%22
https://flohmarkt-zug.twanda.com:8069/store/apps/details?id=com.skgames.trafficracer%22
www.flohmarkt-zug.com/store/apps/details?id=com.skgames.trafficracer%22
www.flohmarkt-zug.com:8069/store/apps/details?id=com.skgames.trafficracer%22
flohmarkt-zug.com/store/apps/details?id=com.skgames.trafficracer%22
flohmarkt-zug.com:8069/store/apps/details?id=com.skgames.trafficracer%22
http://www.flohmarkt-zug.com/store/apps/details?id=com.skgames.trafficracer%22
http://www.flohmarkt-zug.com:8069/store/apps/details?id=com.skgames.trafficracer%22
https://www.flohmarkt-zug.com/store/apps/details?id=com.skgames.trafficracer%22
https://www.flohmarkt-zug.com:8069/store/apps/details?id=com.skgames.trafficracer%22
"""#
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