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.
Example
package main
import (
"fmt"
"regexp"
)
func main() {
var emojiRx = regexp.MustCompile(`[\x{1F600}-\x{1F6FF}|[\x{2600}-\x{26FF}]`)
var str = emojiRx.ReplaceAllString("Thats a nice joke 😆😆😆 😛", `[e]`)
fmt.Println(str)
}
Output
Thats a nice joke 😆😆😆 😛
Most Helpful This Week
Dereferencing a pointer from another package
How to delete or remove element from a Map?
How to use Ellipsis (...) in Golang?
How to print struct variables data in Golang?
How to remove symbols from a string in Golang?
Regular expression to validate phone number
Regular expression to extract filename from given path in Golang
How to check string contains uppercase lowercase character in Golang?
How to wait for Goroutines to Finish Execution?
How to check if a string contains a white space in Golang?
Most Helpful This Week
Find length of Channel, Pointer, Slice, String and MapHow to concatenate two or more slices in Golang?How to Decode or Unmarshal bi-dimensional array of integers?Regular expression to extract domain from URLHow to Unmarshal nested JSON structure?How to read names of all files and folders in current directory?Different ways to validate JSON stringHow to convert Go struct to JSON?How to get Dimensions of an image type jpg jpeg png or gif ?Example of Switch Case with Break in For Loop