+ 2
[SOLVED]a problem in regex
I used replaceAll("[^\\w\\s]", ""] to remove everything except characters and white spaces but digits didn't remove what's my mistake?? later I figured out that I can use [^a-zA-Z\\s] instead but I just wanted to know can I use the first syntax or no that's completely wrong for such thing.
6 Answers
+ 2
\\w will include number and _
so \\w is kinda equal to [a-zA-Z_0-9]
+ 2
I had the same problem as hamid
+ 1
or
.replaceAll("[^\\p{Alpha}\\s]","");
+ 1
zemiak yeah thanks it worked but I never sew \\p or {Alpha} before can you explain about them a bit?
+ 1
thank you so much
0
it is POSIX alternative commands also supported by java regex
https://docs.oracle.com/en/java/javase/14/docs/api/java.base/java/util/regex/Pattern.html