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.
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.
x <- “I like %$@to*&, chew;: gum, but don’t like|}{[] bubble@#^)( gum!?” gsub(“[^[:alnum:][:space:]’]”, “”, x) [1] “I like to chew gum but don’t like bubble gum” The above regex is much more straight forward. It replaces everything that’s not alphanumeric signs, space or apostrophe (caret symbol!) with an empty string.
Using algorithm remove_copy_if :- string text,result; std::remove_copy_if(text.begin(), text.end(), std::back_inserter(result), //Store output std::ptr_fun<int, int>(&std::ispunct) );
Best way to strip punctuation from a string