Doubt | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Doubt

System.out.println(ā€œhello123ā€.replaceAll(ā€œa-zā€,ā€ā€); Output is :hello123 Why? Iam not understanding I want 123 as my output instead it is getting hello123 even after replace method... why?

1st May 2020, 8:14 AM
Haritha Vuppula
Haritha Vuppula - avatar
5 Answers
+ 1
\\D is regex for non-digit char [a-z] is regex for char from a-z group of chars
1st May 2020, 7:21 PM
zemiak
+ 4
Hello There Haritha. You are a bit wrong there. Here's the corrected code : System.out .println("hello123".replaceAll("[a-z]", "")); However, if you want to remove the Capital Letters too then you should write the following : System.out .println("hello123".replaceAll("[A-Za-z]", ""));
1st May 2020, 8:22 AM
Arb Rahim Badsa
Arb Rahim Badsa - avatar
0
or "hello123".replaceAll("\\D","")
1st May 2020, 10:34 AM
zemiak
0
zemiak i didnt understood ur concept what is (ā€œ\\Dā€,ā€ā€)mean
1st May 2020, 5:14 PM
Haritha Vuppula
Haritha Vuppula - avatar
0
Arb Rahim Badsa grt explaination thank you
1st May 2020, 5:15 PM
Haritha Vuppula
Haritha Vuppula - avatar