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 =?

[@#=]

Get Java 9 Regular Expressions now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.