SkillAgentSearch skills...

Ahocorasick

Aho-Corasick string matching algorithm for golang

Install / Use

/learn @gansidui/Ahocorasick
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

ahocorasick

Aho-Corasick string matching algorithm for golang

package main

import (
	"fmt"
	"log"

	"github.com/gansidui/ahocorasick"
)

func main() {
	ac := ahocorasick.NewMatcher()

	dictionary := []string{"hello", "world", "世界", "google", "golang", "c++", "love"}
	ac.Build(dictionary)

	s := "hello世界, hello google, i love golang!!!"
	ret := ac.Match(s)

	for i, _ := range ret {
		original := dictionary[ret[i].Index]
		matched := s[ret[i].EndPosition-len(original) : ret[i].EndPosition]
		if original != matched {
			log.Fatal()
		}
		fmt.Println(original, matched)
	}
}

LICENSE

MIT

View on GitHub
GitHub Stars45
CategoryDevelopment
Updated6mo ago
Forks20

Languages

Go

Security Score

82/100

Audited on Sep 3, 2025

No findings