Nokogiri - 在两个 &quot 之间选择 link

Nokogiri - Selecting a link between two &quot s

我在选择作为嵌入代码一部分的 link 时遇到问题。它在两个 &quot 之间。我已将 link 放入我正在尝试的代码中。

谢谢。

https://gist.githubusercontent.com/anonymous/d2efee7b3967debc531d67de9cc7993a/raw/3f5e0e63ce6fe3aa4cffc2d0afafd2415408308a/gistfile1.txt

正确的形式是。

(?<=&quot;)(.*)(?=&quot;)

输入:

&quot;https://gist.githubusercontent.com/anonymous/d2efee7b3967debc531d67de9cc7993a/raw/3f5e0e63ce6fe3aa4cffc2d0afafd2415408308a/gistfile1.txt&quot;

输出:

https://gist.githubusercontent.com/anonymous/d2efee7b3967debc531d67de9cc7993a/raw/3f5e0e63ce6fe3aa4cffc2d0afafd2415408308a/gistfile1.txt

Ruby代码:

re = /(?<=&quot;)(.*)(?=&quot;)/m
str = '&quot;https://gist.githubusercontent.com/anonymous/d2efee7b3967debc531d67de9cc7993a/raw/3f5e0e63ce6fe3aa4cffc2d0afafd2415408308a/gistfile1.txt&quot;'

# Print the match result
str.scan(re) do |match|
    puts match.to_s
end

测试代码:http://ideone.com/moljMo

参见:https://regex101.com/r/vrBUhc/1