我有这样声明的链接:
link = "<a href=\"https://www.congress.gov/bill/93rd-congress/house-bill/11461\">H.R.11461</a>"
问题是如何使用正则表达式只提取 href 值?
谢谢!
最佳答案
如果你想解析HTML,你可以使用Nokogiri gem 而不是使用正则表达式。这要容易得多。
例子:
require "nokogiri"
link = "<a href=\"https://www.congress.gov/bill/93rd-congress/house-bill/11461\">H.R.11461</a>"
link_data = Nokogiri::HTML(link)
href_value = link_data.at_css("a")[:href]
puts href_value # => https://www.congress.gov/bill/93rd-congress/house-bill/11461
关于ruby - 如何使用 ruby 正则表达式从标签中提取 href?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33245198/