I just found a Regular Expression - replace the word except the URL / URI and change the code this way:
URI_REGEX = %r"((?:(?:[^ :/?#]+):)(?://(?:[^ /?#]*))(?:[^ ?#]*)(?:\?(?:[^ #]*))?(?:#(?:[^ ]*))?)"
def remove_uris(text)
text.split(URI_REGEX).collect do |s|
unless s =~ URI_REGEX
s
end
end.join
end
I am testing it in the rails console and it works as expected:
remove_uris('bla bla bla... bla bla bla... http://bit.ly/someuri bla bla bla...')
=> "bla bla bla... bla bla bla... bla bla bla..."
If someone has a better / effective solution, I will vote or accept it. Thank.
source
share