Is there a way to use \p{Punct}
in a regex in java, but without the two characters (
and )
?
PreviousNext. The character class \p{Punct} matches any punctuation character. The following example shows the usage of Posix character class matching.
The backslash \ is an escape character in Java Strings. That means backslash has a predefined meaning in Java. You have to use double backslash \\ to define a single backslash. If you want to define \w , then you must be using \\w in your regex.
The Difference Between \s and \s+ For example, expression X+ matches one or more X characters. Therefore, the regular expression \s matches a single whitespace character, while \s+ will match one or more whitespace characters.
You should be able to use:
[\p{Punct}&&[^()]]
What this is saying is:
The
punct
character class except for(
and)
.
The ^
character specifies a negative character class. The &&
is an intersection between the punct
class and the custom class for the parenthesis.
Have a look at the Pattern
Javadocs for more info.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With