I am trying to remove any URL within a string, and there is a SO answer that provides a solution using regular expression in PHP:
$regex = "@(https?://([-\w\.]+[-\w])+(:\d+)?(/([\w/_\.#-]*(\?\S+)?[^\.\s])?)?)@";
echo preg_replace($regex, ' ', $string);
I tried directly in Swift as:
myStr.stringByReplacingOccurrencesOfString("@(https?://([-\w\.]+[-\w])+(:\d+)?(/([\w/_\.#-]*(\?\S+)?[^\.\s])?)?)@", withString: "", options: .RegularExpressionSearch)
but it shows some error Invalid escape sequence in literal
.
How to do it correctly in Swift?