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
How to check if a string contains a numbers in Golang?
How to get Dimensions of an image type jpg jpeg png or gif ?
How to use function from another file golang?
Example: How to use ReadFull from IO Package in Golang?
Get Year, Month, Day, Hour, Min and Second from a specified date
How to read input from console line?
Most Helpful This Week
Example: ReadAll, ReadDir, and ReadFile from IO PackageWhat is GOPATH?How to declare empty Map in Go?How to check if a string contains a numbers in Golang?Example: Arrays of Arrays, Arrays of Slices, Slices of Arrays and Slices of SlicesHow to fix race condition using Atomic Functions in Golang?How to Remove duplicate values from Slice?How to extract text from between html tag using Regular Expressions in Golang?How to import structs from another package in Go?How to Convert string to float type in Go?