这是我的字符串,像findstudentbyid
,现在我会根据像find
个单词之前的find
个单词和by
个单词之后的by
,id
这样的关键词进行拆分.
因此,Golang regex模式为`(?i)(^find{1})(\w+)(by{1})(\w+)`
我正在try 拆分这个关键字findstudentbyid
,但我有一个问题,我找不到一个确切的结果,我正在寻找.
我的预期yields 是[find student by id]
或
find
student
by
id
但我无法做到这一点.我确实试过这个golang code
package main
import (
"fmt"
"regexp"
)
func main() {
txt := "findstudentbyid"
re := regexp.MustCompile(`(?i)(^find{1})(\w+)(by{1})(\w+)`)
split := re.Split(txt, -1)
set := []string{}
for i := range split {
set = append(set, split[i])
}
fmt.Println(set)
}