Unicode-safe emoji processing for Go: detect, find, remove, replace, and lookup.
Go
237
21 commits
updated Jul 26, 2026
GoMoji makes it easy to detect, remove, replace, and look up emojis in Go strings.
It solves the common problem that emojis aren't always a single "character"βGoMoji handles them correctly so your string logic just works.
go get -u github.com/forPelevin/gomoji
Create a minimal program that detects and removes emojis:
package main
import (
"fmt"
"github.com/forPelevin/gomoji"
)
func main() {
s := "Hello π world π¦"
fmt.Println(gomoji.ContainsEmoji(s)) // true
fmt.Println(gomoji.RemoveEmojis(s)) // "Hello world "
}
Then run:
go mod init example.com/hello
go get github.com/forPelevin/gomoji@latest
go run .
package main
import "github.com/forPelevin/gomoji"
func main() {
hasEmoji := gomoji.ContainsEmoji("hello world π€")
println(hasEmoji) // true
}
emojis := gomoji.FindAll("π§ hello π¦ world")
// Returns slice of Emoji structs with detailed information
cleaned := gomoji.RemoveEmojis("π§ hello π¦ world")
println(cleaned) // "hello world"
// Replace with a specific character
replaced := gomoji.ReplaceEmojisWith("π§ hello π¦ world", '_')
println(replaced) // "_ hello _ world"
// Replace with custom function
customReplaced := gomoji.ReplaceEmojisWithFunc("π§ hello π¦ world", func(em Emoji) string {
return em.Slug
})
println(customReplaced) // "person-in-steamy-room hello butterfly world"
info, err := gomoji.GetInfo("π¦")
if err == nil {
println(info.Slug) // "butterfly"
println(info.UnicodeName) // "E3.0 butterfly"
println(info.Group) // "Animals & Nature"
}
type Emoji struct {
Slug string `json:"slug"` // Unique identifier
Character string `json:"character"` // The emoji character
UnicodeName string `json:"unicode_name"` // Official Unicode name
CodePoint string `json:"code_point"` // Unicode code point
Group string `json:"group"` // Emoji group category
SubGroup string `json:"sub_group"` // Emoji subgroup category
}
ContainsEmoji(s string) bool - Checks if a string contains any emojiFindAll(s string) []Emoji - Finds all unique emojis in a stringCollectAll(s string) []Emoji - Finds all emojis including repeats (preserves order)RemoveEmojis(s string) string - Removes all emojis from a stringReplaceEmojisWith(s string, c rune) string - Replaces emojis with a specified characterReplaceEmojisWithSlug(s string) string - Replaces emojis with their slugsReplaceEmojisWithFunc(s string, replacer func(Emoji) string) string - Replaces emojis via a custom functionGetInfo(emoji string) (Emoji, error) - Gets detailed information about an emoji; returns ErrStrNotEmoji if not foundAllEmojis() []Emoji - Returns all available emojisFor full reference documentation generated from source, see the package docs on pkg.go.dev: github.com/forPelevin/gomoji.
GoMoji automatically stays up-to-date with the latest Unicode emoji standards through our automated update system:
GoMoji is designed for high performance, with parallel processing capabilities for optimal speed. Here are the key benchmarks:
| Operation | Sequential Performance | Parallel Performance | Allocations |
|---|---|---|---|
| Contains Emoji | 57.49 ns/op | 7.167 ns/op | 0 B/op, 0 allocs/op |
| Remove Emojis | 1454 ns/op | 201.4 ns/op | 68 B/op, 2 allocs/op |
| Find All | 1494 ns/op | 313.8 ns/op | 288 B/op, 2 allocs/op |
| Get Info | 8.591 ns/op | 1.139 ns/op | 0 B/op, 0 allocs/op |
| Replace With Slug | 3822 ns/op | 602.4 ns/op | 160 B/op, 3 allocs/op |
Full benchmark details:
go test -bench=. -benchmem -v -run Benchmark ./...
goos: darwin
goarch: arm64
pkg: github.com/forPelevin/gomoji
cpu: Apple M1 Pro
BenchmarkContainsEmojiParallel-10 164229604 7.167 ns/op 0 B/op 0 allocs/op
BenchmarkContainsEmoji-10 20967183 57.49 ns/op 0 B/op 0 allocs/op
BenchmarkReplaceEmojisWithSlugParallel-10 2160638 602.4 ns/op 160 B/op 3 allocs/op
BenchmarkReplaceEmojisWithSlug-10 309879 3822 ns/op 160 B/op 3 allocs/op
BenchmarkRemoveEmojisParallel-10 5794255 201.4 ns/op 68 B/op 2 allocs/op
BenchmarkRemoveEmojis-10 830334 1454 ns/op 68 B/op 2 allocs/op
BenchmarkGetInfoParallel-10 989043939 1.139 ns/op 0 B/op 0 allocs/op
BenchmarkGetInfo-10 139558108 8.591 ns/op 0 B/op 0 allocs/op
BenchmarkFindAllParallel-10 4029028 313.8 ns/op 288 B/op 2 allocs/op
BenchmarkFindAll-10 751990 1494 ns/op 288 B/op 2 allocs/op
Note: Benchmarks were performed on Apple M1 Pro processor. Your results may vary depending on hardware.
RemoveEmojis/Replace* or handle this explicitly.golang.org/x/text packages) alongside this library.Contributions are welcome! Please feel free to submit a Pull Request.
make lint-fix (uses goimports, gofmt, and golangci-lint).make test or go test ./....make bench).GoMoji is available under the MIT License. GoMoji source code is available under the MIT License.
284 followers Β· starred Jan 2021
819 followers Β· starred Jan 2024
500 followers Β· starred May 2023
Unicode-safe emoji processing for Go: detect, find, remove, replace, and lookup.
Go
237
21 commits
updated Jul 26, 2026
GoMoji makes it easy to detect, remove, replace, and look up emojis in Go strings.
It solves the common problem that emojis aren't always a single "character"βGoMoji handles them correctly so your string logic just works.
go get -u github.com/forPelevin/gomoji
Create a minimal program that detects and removes emojis:
package main
import (
"fmt"
"github.com/forPelevin/gomoji"
)
func main() {
s := "Hello π world π¦"
fmt.Println(gomoji.ContainsEmoji(s)) // true
fmt.Println(gomoji.RemoveEmojis(s)) // "Hello world "
}
Then run:
go mod init example.com/hello
go get github.com/forPelevin/gomoji@latest
go run .
package main
import "github.com/forPelevin/gomoji"
func main() {
hasEmoji := gomoji.ContainsEmoji("hello world π€")
println(hasEmoji) // true
}
emojis := gomoji.FindAll("π§ hello π¦ world")
// Returns slice of Emoji structs with detailed information
cleaned := gomoji.RemoveEmojis("π§ hello π¦ world")
println(cleaned) // "hello world"
// Replace with a specific character
replaced := gomoji.ReplaceEmojisWith("π§ hello π¦ world", '_')
println(replaced) // "_ hello _ world"
// Replace with custom function
customReplaced := gomoji.ReplaceEmojisWithFunc("π§ hello π¦ world", func(em Emoji) string {
return em.Slug
})
println(customReplaced) // "person-in-steamy-room hello butterfly world"
info, err := gomoji.GetInfo("π¦")
if err == nil {
println(info.Slug) // "butterfly"
println(info.UnicodeName) // "E3.0 butterfly"
println(info.Group) // "Animals & Nature"
}
type Emoji struct {
Slug string `json:"slug"` // Unique identifier
Character string `json:"character"` // The emoji character
UnicodeName string `json:"unicode_name"` // Official Unicode name
CodePoint string `json:"code_point"` // Unicode code point
Group string `json:"group"` // Emoji group category
SubGroup string `json:"sub_group"` // Emoji subgroup category
}
ContainsEmoji(s string) bool - Checks if a string contains any emojiFindAll(s string) []Emoji - Finds all unique emojis in a stringCollectAll(s string) []Emoji - Finds all emojis including repeats (preserves order)RemoveEmojis(s string) string - Removes all emojis from a stringReplaceEmojisWith(s string, c rune) string - Replaces emojis with a specified characterReplaceEmojisWithSlug(s string) string - Replaces emojis with their slugsReplaceEmojisWithFunc(s string, replacer func(Emoji) string) string - Replaces emojis via a custom functionGetInfo(emoji string) (Emoji, error) - Gets detailed information about an emoji; returns ErrStrNotEmoji if not foundAllEmojis() []Emoji - Returns all available emojisFor full reference documentation generated from source, see the package docs on pkg.go.dev: github.com/forPelevin/gomoji.
GoMoji automatically stays up-to-date with the latest Unicode emoji standards through our automated update system:
GoMoji is designed for high performance, with parallel processing capabilities for optimal speed. Here are the key benchmarks:
| Operation | Sequential Performance | Parallel Performance | Allocations |
|---|---|---|---|
| Contains Emoji | 57.49 ns/op | 7.167 ns/op | 0 B/op, 0 allocs/op |
| Remove Emojis | 1454 ns/op | 201.4 ns/op | 68 B/op, 2 allocs/op |
| Find All | 1494 ns/op | 313.8 ns/op | 288 B/op, 2 allocs/op |
| Get Info | 8.591 ns/op | 1.139 ns/op | 0 B/op, 0 allocs/op |
| Replace With Slug | 3822 ns/op | 602.4 ns/op | 160 B/op, 3 allocs/op |
Full benchmark details:
go test -bench=. -benchmem -v -run Benchmark ./...
goos: darwin
goarch: arm64
pkg: github.com/forPelevin/gomoji
cpu: Apple M1 Pro
BenchmarkContainsEmojiParallel-10 164229604 7.167 ns/op 0 B/op 0 allocs/op
BenchmarkContainsEmoji-10 20967183 57.49 ns/op 0 B/op 0 allocs/op
BenchmarkReplaceEmojisWithSlugParallel-10 2160638 602.4 ns/op 160 B/op 3 allocs/op
BenchmarkReplaceEmojisWithSlug-10 309879 3822 ns/op 160 B/op 3 allocs/op
BenchmarkRemoveEmojisParallel-10 5794255 201.4 ns/op 68 B/op 2 allocs/op
BenchmarkRemoveEmojis-10 830334 1454 ns/op 68 B/op 2 allocs/op
BenchmarkGetInfoParallel-10 989043939 1.139 ns/op 0 B/op 0 allocs/op
BenchmarkGetInfo-10 139558108 8.591 ns/op 0 B/op 0 allocs/op
BenchmarkFindAllParallel-10 4029028 313.8 ns/op 288 B/op 2 allocs/op
BenchmarkFindAll-10 751990 1494 ns/op 288 B/op 2 allocs/op
Note: Benchmarks were performed on Apple M1 Pro processor. Your results may vary depending on hardware.
RemoveEmojis/Replace* or handle this explicitly.golang.org/x/text packages) alongside this library.Contributions are welcome! Please feel free to submit a Pull Request.
make lint-fix (uses goimports, gofmt, and golangci-lint).make test or go test ./....make bench).GoMoji is available under the MIT License. GoMoji source code is available under the MIT License.
284 followers Β· starred Jan 2021
819 followers Β· starred Jan 2024
500 followers Β· starred May 2023