hpricot:An Hpricot Showcase:Hpricot Challenge:Wildcard in Attribute Search

まんま

require "hpricot"

X =<<EOS
<a href="blah.com" id="p-1">Some text</a>
<a href="blah.com" id="p-2">Some text</a>
<a href="blah.com" id="p-3">Some text</a>
<a href="blah.com" id="P-4">Some text</a>
EOS

doc = Hpricot(X)
p doc/"a[@id^=p-]"

で、

#<Hpricot::Elements[{elem <a href="blah.com" id="p-1"> "Some text" </a>}, {elem <a href="blah.com" id="p-2"> "Some text" </a>}, {elem <a href="blah.com" id="p-3"> "Some text" </a>}]>