Match Jsoup with regex
You can use the initial CSS selector ^=
. It is supported by Jsoups .select(...)
.
You can do it as follows:
doc.select("div[id^=shout]");
This is a complete example:
public static void main(String[] args) { Document parse = Jsoup.parse("<div id=\"shout_23\"/>" + "<div id=\"shout_42\"/>" + "<div id=\"notValidId\"/>" + "<div id=\"shout_1337\"/>"); Elements divs = parse.select("div[id^=shout"); for (Element element : divs) { System.out.println(element); } }
He will print:
<div id="shout_23"></div> <div id="shout_42"></div> <div id="shout_1337"></div>