Pattern p2 = Pattern.compile(".*");
Matcher m2 = p2.matcher("true");
System.out.println(m2.matches() + " [" + m2.group() + "]");
When I use the code above it is all right. But I don’t understand what is going on when I use this regexpr [.]*. It prints false.
How to make a dot as a specific symbol? Or how to make a class of symbols with any characters without \n and \r?
Because inside a character class, the dot loses its special meaning and will match a plain old dot (the
.character).Outside of a character class the dot is a metacharacter that matches any character, excluding newlines (unless you use the
Pattern.DOTALLmodifier, of course).Use a negated character class:
[^\r\n]means “match anything that’s not a\ror a\n.