O'Reilly logo

Java 9 Regular Expressions by Anubhava Srivastava

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Negated character classes

By placing the carrot character (^) in the first position inside a character class (just next to [) negates the matching of the character class. A negated character class matches any character that is not included in the class. A negated character class also negates a character range by matching any character not matched by the character range.

You learned in Chapter 1, Getting Started with Regular Expressions, that dot (.) matches any character except the newline character. However, note that the negated character class also matches newline characters such as \r, \n, and so on.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required