1

URI.extractはこれを行うと主張していますが、一致する括弧を処理しません:

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

かっこで囲まれた URL を壊さずにテキストから URL を抽出する最良の方法 (ユーザーが使用したい方法) は何ですか?

4

3 に答える 3

0

URL が常に括弧で区切られている場合は、正規表現の方が適切なソリューションである可能性があります。

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 /\(([^\)]*)\)/
于 2010-06-08T03:42:06.053 に答える
-1

この正規表現を使用して、文字列から URL を抽出できます

"some thing http://abcd.com/ and http://google.com are great".scan(/(?:http|https):\/\/[a-z0-9]+(?:[\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(?:(?::[0-9]{1,5})?\/[^\s]*)?/ix)
于 2013-02-08T05:18:13.163 に答える
-1

ご使用前に

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

これを追加する必要があります

require 'uri'
于 2013-02-08T05:07:41.203 に答える