I'm receiving HTML code from XML and trying to find last in Java. when I'm running the code I always receive the first span and the groupCount show me that there is only one match (the first one). I also tried to use a hardcode version of the XML (I created a string variable and still got the same result)
here is my code:
String text = "<div><ul ><li><span>answer 1.</span></li><li><span>answer 2</span></li><li><span>answer3.</span></li><li><span>answer 4</span></li></ul><div><span>Cat 1 | Cat 2 | Cat 3</span></div></div>"
Pattern pattern3 = Pattern.compile("<span.*?(?=</span>)");
Matcher matcher3 = pattern3.matcher(desc);
if (matcher3.find()) {
int result = matcher3.groupCount();
String s = (matcher3.group(result))//->>always show the first result
}