Reputation: 3936
I'm using JSOUP, and trying to get the elements which start with a particular div tag id. For example:
<div id="test123">.
I need to check if the elements starts with the string "test" and get all the elements.
I looked at http://jsoup.org/cookbook/extracting-data/selector-syntax and I tried a multiple variations using:
doc.select("div:matches(test(*))");
But it still didn't work. Any help would be much appreciated.
Upvotes: 2
Views: 2045
Reputation: 1108692
Use the attribute-starts-with selector [attr^=value]
.
Elements elements = doc.select("div[id^=test]");
// ...
This will return all <div>
elements with an id
attribute starting with test
.
Upvotes: 3