I need to check any sentence against the following pattern:
A sentence that consist of two or more questions
So for example the following sentences all matches with this pattern:
why do you look at me? Are you alright?
I am sick. How are you?. Well you do not have to answer it. what's up?
How are you?I am sick.what's up? Well you do not have to answer it.
so since it was a little bit complicated for me I tried with just recognizing a simple question so I wrote my code this way:
regx:
^[why|who|where|when|how|did|do|were|was|would|will|should|could|can]\\S+?$
Java code:
private static void questionInRow(String commentstr){
String urlPattern = "^[why|who|where|when|how|did|do|were|was|would|will|should|could|can]\\S+?$";
Pattern p = Pattern.compile(urlPattern,Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher(commentstr);
if (m.find()) {
System.out.println("yes");
}
}
But even when I ran that code it does not work with this sentence:
why I love u?
So first, what is wrong with query and also I do not know how can I define my regular expression to check for this pattern:
A sentence that consist of two or more questions
any help appreciated.