How do I do a regex search in Nokogiri for text that matches a certain beginning?

后端 未结 4 606
无人及你
无人及你 2021-02-03 22:50

Given:

require \'rubygems\'
require \'nokogiri\'
value = Nokogiri::HTML.parse(<<-HTML_END)
\"

  

A

4条回答
  •  迷失自我
    2021-02-03 23:16

    Use the xpath function starts-with:

    value.xpath('//p[starts-with(@id, "para-")]').each { |x| puts x['id'] }
    

提交回复
热议问题