Remove all alpha characters from a string by using regex - Android java.util.regex

Android examples for java.util.regex:Character Pattern

Description

Remove all alpha characters from a string by using regex

Demo Code


public class Main{

    /**/*  w w  w  .  j a v a  2 s.c  om*/
     * Remove all alpha characters from a string
     * @param str   String to parse
     * @return      Return a string without alpha characters, only numeric characters
     */
    public static String removeAlphaCharacters(String str) {
        return str.replaceAll("[^\\d.]", "");
    }

}

Related Tutorials