When I am trying to explode the url from one string, its not returning the actual URL. Please find the def I have used
def self.getUrlsFromString(str="")
url_regexp = /(?:http|https):\/\/[a-z0-9]+(?:[\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(?:(?::[0-9]{1,5})?\/[^\s]*)?/ix
url = str.split.grep(url_regexp)
return url
rescue Exception => e
DooDooLogger.log(e.message,e)
return ""
end
when I do self.getUrlsFromString(" check this site...http://lnkd.in/HjUVii") it’s returning
Instead of
It’s because grep in Array class returns an array of every element for element === pattern, so
will return [“site…http://lnkd.in/HjUVii“] too.
You can try instead of
something like this: