The following is my code:
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {
public static void main(String args[]) {
String pageText = "Other Strings 9.5.1 My Other Strings";
String pageText2 = "Other Strings 9.3.1.1.1 My Other Strings";
Pattern anyServicePattern = Pattern.compile("(\d+\.){2}[0-9]\s+[a-zA-Z]+");
Matcher anyServiceMatcher = anyServicePattern.matcher(pageText);
if (anyServiceMatcher.find()) {
System.out.println("Found");
} else {
System.out.println("Not Found");
}
Matcher anyServiceMatcher2 = anyServicePattern.matcher(pageText2);
if (anyServiceMatcher2.find()) {
System.out.println("Found");
} else {
System.out.println("Not Found");
}
}
}
It prints:
Found
Found
I want it to print
Found
Not Found
i.e. I want the regular expression should match the pattern <whatever characters><any number><dot><any number><dot><any number><single space><whatever characters>
I tried many combinations, but to my high surprise couldn’t crack it. What is the correct expression?
Here is the jdoodle link: https://www.jdoodle.com/ia/14IW