How to remove all digits from a string using regex in Kotlin

1 Answer

0 votes
fun main() {
    var s = "abs322kl59po@#d0057qn8"
    
    // Create a regular expression to match digits
    val digitsRegex = Regex("[0-9]")
    
    // Use replace to replace digit characters with an empty string
    s = digitsRegex.replace(s, "")
    
    println(s)
}



 
/*
run:

absklpo@#dqn
 
*/

 



answered Dec 10, 2024 by avibootz
...