a problem in regex | SoloLearn: Learn to code for FREE!

+2

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.

8/13/2020 3:36:07 PM

hamid

6 Answers

New Answer

+2

\\w will include number and _ so \\w is kinda equal to [a-zA-Z_0-9]

+1

or .replaceAll("[^\\p{Alpha}\\s]","");

+1

I had the same problem as hamid

0

zemiak yeah thanks it worked but I never sew \\p or {Alpha} before can you explain about them a bit?

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

0

thank you so much