How to remove non-alphabets from a String

This post is all about how to remove all characters that are not alphabets from a String. For the reverse of the same, refer here. For eg, if you want to only "ABC" from "A1@348474B*&C" then the following snippet of code would be fine in Java.

String test = "A1@348474B*&C";
test = test.replaceAll("[a-zA-Z]",""); //This will replace all non alpha characters
System.out.println("The extracted String is "+test);

The output of the above code will be,

The extracted String is ABC

Hope this was helpful to you in someway. Happy Working...

Comments

Popular posts from this blog

Changing Timezone in Postgresql, Ubuntu

My 10 years in Application Development

Dissecting Openbravo 3.0 UI Architecture