import Foundation
let pattern = ##"(?:[a-z]{3,9}:\/\/?[\-;:&=\+\$,\w]+?[a-z0-9\.\-]+|[\/a-z0-9]+\.|[\-;:&=\+\$,\w]+@)[a-z0-9\.\-]+(?:(?:\/[\+~%\/\.\w\-_]*)?\??[\-\+=&;%@\.\w_]*#?[\.\!\/\\\w]*)?"##
let regex = try! NSRegularExpression(pattern: pattern, options: .caseInsensitive)
let testString = ##"[PT]Consultório de dentista equipado e pronto //sssss.ssss.sss a funcionar.<br />Com la/boratório, sala de espera, escritório e wc.<br />Alarme instalado. Sistema de som interligado para todas as divisões.<br />Prédio com porteiro.<br />2 minutos (a pé) da estação de metro da Trindade.<br /><br />Fotos 360º:<br /><br />Consultório + Laboratório<br />https://photosynth.net/view.aspx?cid=f0e5b9db-fdec-4e50-9a83-69d7c2bc44e7<br /><br />Escritório<br />https://photosynth.net/view.aspx?cid=da4c64fe-c4cf-45f5-8bf9-ff62d369e98a<br /><br />Sala de espera<br />https://photosynth.net/view.aspx?cid=b631fd55-f7e7-41b3-a9a2-2f687dffeec8[/PT][EN]Consultório + Laboratório<br />http://photosynth.net/view.aspx?cid=f0e5b9db-fdec-4e50-9a83-69d7c2bc44e7[/EN][FR]Consultório + Laboratório<br />www.photosynth.net/view.aspx?cid=f0e5b9db-fdec-4e50-9a83-69d7c2bc44e7[/FR]"##
let stringRange = NSRange(location: 0, length: testString.utf16.count)
let substitutionString = #"(url)$U"#
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