(Sorry for my earlier error. Brain now firmly engaged. Er, probably.)
This works:
String rex = "^\\d+\\.\\s\\p{Lu}+.*";
System.out.println("1. PTYU fmmflksfkslfsm".matches(rex));
// true
System.out.println(". PTYU fmmflksfkslfsm".matches(rex));
// false, missing leading digit
System.out.println("1.PTYU fmmflksfkslfsm".matches(rex));
// false, missing space after .
System.out.println("1. xPTYU fmmflksfkslfsm".matches(rex));
// false, lower case letter before the upper case letters
Breaking it down:
- ^= Start of string
- \d+= One or more digits (the- \is escaped because it's in a string, hence- \\)
- \.= A literal- .(or your original- [.]is fine) (again, escaped in the string)
- \s= One whitespace char (no need for the- {1}after it) (I'll stop mentioning the escapes now)
- \p{Lu}+= One or more upper case letters (using the proper Unicode escape — thank you, tchrist, for pointing this out in your comment below. In English terms, the equivalent would be- [A-Z]+)
- .*= Anything else
See the documentation here for details.
You only need the .* at the end if you're using a method like String#match (above) that will try to match the entire string.