I want to check if the text contains a number and is not a question, so I wrote the following Java code using a regular expression:
private static void containNumberNoQ(String commentstr){
String urlPattern = "[^?]\\s\\d[^?]";
Pattern p = Pattern.compile(urlPattern,Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher(commentstr);
if (m.find()) {
System.out.println("yes");
}
}
But when I try this with the following sentence, it matches, although the sentence has a question mark:
just 2% of the result?
Why?
source
share