How to replace a substring with a link(http) in swift 3? -
i have string , substring(http) , want replace substring don't know when substring end. mean want check until 1 space not coming , after want replace it. checking if string contains http string want replace when space come.
here below example :-
let string = "hello.world http://www.google.com way good".
this string can dynamic mean in above string http there, want replace "http://www.google.com" "website".
string = "hello.world website way good"
a possible solution regular expression
the pattern searches http://
or https://
followed 1 or more non-whitespace characters word boundary.
let string = "hello.world http://www.google.com way good" let trimmedstring = string.replacingoccurrences(of: "https?://\\s+\\b", with: "website", options: .regularexpression) print(trimmedstring)
Comments
Post a Comment