I have a question about finding html tags using Java and Regex.
I use the code below to find all tags in HTML, documentURL is obviously the HTML content.
The find method returns true, which means that it can find something in the HTML, but the matches () method always returns false, and I'm completely and completely puzzled by this.
I also referenced the Java documentation, but could not find the answer.
What is the correct way to use matcher?
Pattern keyLineContents = Pattern.compile("(<.*?>)"); Matcher keyLineMatcher = keyLineContents.matcher(documentURL); boolean result = keyLineMatcher.find(); boolean matchFound = keyLineMatcher.matches();
Doing something like this leads to release:
String abc = keyLineMatcher.group(0);
Thanks.
source share