Im trying to use regular expressions to identify xhtml tags in a file and then show how many in total and how many of each unique tag there is in the file.
This is just a test to make sure it recognizes < and > as a tag but it doesnt seem to be working :
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegularExpExp {
public static void main(String[] args) {
String inputStr = " <p> "; // a random tag to see if it works
Pattern pattern = Pattern.compile("< .* >"); // that should mean "<" anything at all ">"
Matcher matcher = pattern.matcher(inputStr);
if (matcher.matches()) {
System.out.println("Matched");
} else {
System.out.println("Not Matched");
}
}
}
Well it always shows "Not matched". I'm lost, please reply.