Replace Non Alphabetic Characters

This program removes non alphabetic characters from string using regex.

Problem Statement

Write a Java program to remove non alphabetic characters from "Eduinq123@Test!".

Source Code

1 public class RegexReplaceNonAlpha {
2 public static void main(String[] args) {
3 System.out.println("Eduinq Regex Replace Non Alpha");
4 String str="Eduinq123@Test!";
5 String result=str.replaceAll("[^A-Za-z]","");
6 System.out.println("After removal: "+result);
7 }
8 }

Program Output

Eduinq Regex Replace Non Alpha
After removal: EduinqTest

Explanation

Regex [^A-Za-z] matches non alphabetic characters. - replaceAll() removes them. - Together demonstrates regex cleaning. Conclusion: Shows how to remove non alphabetic characters using regex.

Quick Links to Explore