package main import ( "fmt" "regexp" ) func main() { input := "The quick brown fox jumped over the lazy dog." re := regexp.MustCompile(`\b\w{5}\b`) // matches all words with exactly 5 letters output := re.ReplaceAllString(input, "*****") fmt.Println(output) }
The quick ***** **** jumped over the lazy ****.
package main import ( "fmt" "regexp" ) func main() { input := "Hello, 1234 world!" re := regexp.MustCompile(`\d+`) // matches one or more digits output := re.ReplaceAllString(input, "") fmt.Println(output) }
Hello, world!In both examples, we used the `regexp` package from the Go standard library.