1

What is a good way to find URL's in a string that may or may not be preceded by HTTP or HTTPS?

For example:

Here is some text. It has one url here: www.example.com. It also has other link 
that goes to http://foo.bar.net and then some more text.

What is a good way to find the URL's?

I am mostly concerned about ".com", ".net", ".org", ".gov", ".edu", and ".us".

I am using Ruby 1.9.3.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
B Seven
  • 44,484
  • 66
  • 240
  • 385
  • Possible duplicate: http://stackoverflow.com/questions/4716513/ruby-regular-expression-to-match-a-url, which links to http://stackoverflow.com/questions/1141848/regex-to-match-url – Robert Harvey May 20 '13 at 21:54
  • There's also this: http://stackoverflow.com/q/13198997 – Robert Harvey May 20 '13 at 21:56
  • Twitter has released a gem that can help with extracting URLs from a string: [twitter-text-rb](https://github.com/twitter/twitter-text-rb). Is (auto)linking your goal or just extracting the URLs? – Thomas Klemm May 20 '13 at 22:01
  • @ThomasKlemm - Yes, autolinking is the goal, but I need to add a tag. – B Seven May 20 '13 at 22:04
  • You might have a look at [**Rinku**](https://github.com/vmg/rinku), it should allow you to wrap links in custom tags or add attributes. More options: [Autolinking in pluginGeek](http://www.plugingeek.com/categories/autolinking-and-embedding-content-ruby) – Thomas Klemm May 20 '13 at 23:20

0 Answers0