Home  >  Article  >  Backend Development  >  How to Replace Emojis with Regex in Go?

How to Replace Emojis with Regex in Go?

Linda Hamilton
Linda HamiltonOriginal
2024-11-22 21:45:16520browse

How to Replace Emojis with Regex in Go?

How to replace emoji characters in string using regex in golang

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn