How to replace emoji characters in string using regex in Golang?

Replace emoji characters in String
In the following program ReplaceAllString() method is used, which allows us to replace original string with another string if the specified string matches with the specified regular expression. This method is defined under the regexp package, hence to access ReplaceAllString() method first we need to import the regexp package in our program.


package main

import (

func main() {
	var emojiRx = regexp.MustCompile(`[\x{1F600}-\x{1F6FF}|[\x{2600}-\x{26FF}]`)
	var str = emojiRx.ReplaceAllString("Thats a nice joke 😆😆😆 😛", `[e]`)


Thats a nice joke 😆😆😆 😛

Most Helpful This Week