+ 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 RĂ©ponses
+ 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