First of all,i want to remove all punctuations of a String.I wrote the following code.
Pattern pattern = Pattern.compile("\\p{Punct}");
Matcher matcher = pattern.matcher("!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~(hello)");
if (matcher.find())
System.out.println(matcher.replaceAll(""));
after repalcement i got the output: (hello)
so the pattern matches the One of !"#$%&'()*+,-./:;<=>?@[]^_`{|}~ which is in accord with the official Docs:https://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html
But i want to remove "(" Fullwidth Left Parenthesis U+FF08* and ")" Fullwidth Right Parenthesis U+FF09as well,so i change my code to this:
Pattern pattern = Pattern.compile("(?U)\\p{Punct}");
Matcher matcher = pattern.matcher("!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~()");
if (matcher.find())
System.out.println(matcher.replaceAll(""));
after repalcement i got the output: $+<=>^`|~
The matcher indeed match "(" Fullwidth Left Parenthesis U+FF08* and ")" Fullwidth Right Parenthesis U+FF09
But miss $+<=>^`|~
I am so confused why did that happen? Can anyone give some help? Thanks in advance!