Programming Language/kotlin

kotiln // 정규표현식 문자열에서 숫자만 남기기

Jaybon 2021. 1. 7. 14:33

toRegex() 함수 사용

fun main() {

    var testRegex = """[\D]""".toRegex();
    println(testRegex.replace("!@#57 -/312\$F 1ASD1326 450 !~",""))

    var test = "!@#57 -/312\$F 1ASD1326 450 !~";
    print(test.replace("[\\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