Check if string is a punctuation character

Here is one way to do it with regular expressions:

if (Pattern.matches("\\p{Punct}", str)) {
    ...
}

The \p{Punct} regular expression is a POSIX pattern representing a single punctuation character.

Leave a Comment