You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
690 B
Go

package trie
import (
"fmt"
"regexp"
"testing"
)
func TestTrie(t *testing.T) {
trie := NewTrie()
// 指令集
words := []string{"j", "c", "w", "s", "m"}
// 构建 前缀树
for _, word := range words {
trie.Insert(word)
}
// 待搜索的连续指令 玩家自由搭配
search := "jc3sm1c2m2c4m3" // 加入游戏 生产3 上路兵 生产2 中路兵 生产4 下路兵
if trie.Exists(search) {
fmt.Println("可以用 ", search)
} else {
fmt.Println("啊 还没能匹配", search)
}
var exp = `([jJ])|([sS])|([cC]\d)|([mM]\d)`
compile, err := regexp.Compile(exp)
if err != nil {
return
}
allString := compile.FindAllString(search, -1)
fmt.Println(allString)
}