입력받은 전화번호 등에서 하이픈이나 스페이스 같은 필요없는 문자를 제거할 때 사용하자

public class Test1 {

    public static void main(String[] args) {

        String test = "!@#$@#826 $@#1%$%7 98$asd87 9f320qepu as dfkjl321";
        System.out.println(test.replaceAll("[\\D]",""));
        System.out.println(test.replaceAll("\\D",""));
        System.out.println(test.replaceAll("[^\\d]",""));
        System.out.println(test.replaceAll("^\\d",""));

    }
}

 

결과

 

regex101.com/r/FIXIWL/1/

 

Online regex tester and debugger: PHP, PCRE, Python, Golang and JavaScript

Please wait while the app is loading...

regex101.com

 

+ Recent posts