Remove Digits from String
This program removes digits from a string using regex.
Problem Statement
Write a Java program to remove all digits from a given string.
Source Code
| 1 | public class RegexReplace { |
| 2 | public static void main(String[] args) { |
| 3 | System.out.println("Eduinq Regex Replace"); |
| 4 | String str="Eduinq123Test456"; |
| 5 | String result=str.replaceAll("\\d",""); |
| 6 | System.out.println("String after removal: "+result); |
| 7 | } |
| 8 | } |
Program Output
Eduinq Regex Replace String after removal: EduinqTest
Explanation
Regex \\d matches digits. - replaceAll() replaces all digits with empty string. - Together demonstrates regex replacement. - Useful for sanitizing input strings. Conclusion: Shows how to remove digits from string using regex.