Home > Article > Backend Development > How to Replace Emojis with Regex in Go?
We are going to use ReplaceAllString function of regexp package in Go with a regular expression to replace all the emoji characters in a string.
package main import ( "fmt" "regexp" ) func main() { var emojiRx = regexp.MustCompile(`[\x{1F600}-\x{1F6FF}|[\x{2600}-\x{26FF}]`) var s = emojiRx.ReplaceAllString("Thats a nice joke ??? ? -> Thats a nice joke [e][e][e] [e]", `[e]`) fmt.Println(s) }
Output:
Thats a nice joke [e][e][e] [e]
The above is the detailed content of How to Replace Emojis with Regex in Go?. For more information, please follow other related articles on the PHP Chinese website!