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

How to Replace Emojis with Regex in Go?

Linda Hamilton
Release: 2024-11-22 21:45:16
Original
628 people have browsed it

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)    
}
Copy after login

Output:

Thats a nice joke [e][e][e] [e]
Copy after login

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 of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template