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

1 Answer

0 votes
package main

import (
    "fmt"
    "regexp"
)

func main() {
    s := "abs322kl59po@$d0057qn8"

    // Create a regular expression to match digits
    digitsRegex := regexp.MustCompile("[0-9]")

    // Use ReplaceAllString to replace digit characters with an empty string
    s = digitsRegex.ReplaceAllString(s, "")

    fmt.Println(s)
}



/*
run:

absklpo@$dqn

*/

 



answered Dec 10, 2024 by avibootz
...