views:

75

answers:

1

URI.extract claims to do this, but it doesn't handle matched parens:

>> URI.extract("text here (http://foo.example.org/bla) and here")
=> ["http://foo.example.org/bla)"]

What's the best way to extract URLs from text without breaking parenthesized URLs (which users like to use)?

A: 

If the URLs are always bound by parentheses a Regular Expression might be a better solution.

text = "text here (http://foo.example.org/bla) and here and here is (http://yet.another.url/with/parens) and some more text"
text.scan /\(([^\)]*)\)/
Jacob Tomaw