How to remove punctuation from a string in Go

1 Answer

0 votes
package main

import (
	"fmt"
	"regexp"
	"strings"
)

func main() {
	str := "Go: is a statically typed, compiled high-level, ~!@#$%^&*() programm[i]ng language."

	re := regexp.MustCompile(`[^\w\s]|_`)
	str = re.ReplaceAllString(str, "")
	str = strings.Join(strings.Fields(str), " ")

	fmt.Println(str)
}


/*
run:

Go is a statically typed compiled highlevel programming language

*/

 



answered Jul 31, 2024 by avibootz

Related questions

1 answer 35 views
35 views asked Nov 23, 2024 by avibootz
1 answer 66 views
1 answer 39 views
...