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

Examples of character classes

Which regex will match the letters p, m, or z?

Solution 1:

    [pmz]

Solution 2:

    [zmp]

Solution 3:

    [mzp]

All the preceding three regular expressions will behave in exactly the same manner because the order of the characters inside the character class does not matter.

Which regex will match English language vowels a, e, i, o, and u?

    [aeiou]

Which regex will match the field extensions .mp3 or .mp3?

    \.mp[34]

Which regex will match the letters @, #, or =?

[@#=]

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