+ 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.

13th Aug 2020, 3:36 PM
hamid
hamid - avatar
6 Respostas
+ 2
\\w will include number and _ so \\w is kinda equal to [a-zA-Z_0-9]
13th Aug 2020, 3:46 PM
Taste
Taste - avatar
+ 2
I had the same problem as hamid
13th Aug 2020, 4:56 PM
Mohammad.R7
+ 1
or .replaceAll("[^\\p{Alpha}\\s]","");
13th Aug 2020, 4:28 PM
zemiak
+ 1
zemiak yeah thanks it worked but I never sew \\p or {Alpha} before can you explain about them a bit?
13th Aug 2020, 6:47 PM
hamid
hamid - avatar
+ 1
thank you so much
13th Aug 2020, 7:48 PM
hamid
hamid - avatar
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
13th Aug 2020, 7:44 PM
zemiak