在Go中的字符串列表上拆分字符串

Jam*_*ner 3 string split go string-split

是否有可能不仅拆分一个字符串而且拆分一串字符串?即

strings.Split("Dogs and Cats are Great", "and"))
Run Code Online (Sandbox Code Playgroud)

但不是使用一个字符串,而是使用一段字符串:

strings.Split("Dogs and Cats are Great", []string{"and", "are"}))
Run Code Online (Sandbox Code Playgroud)

Jim*_*imB 5

您可以使用正则表达式:http://play.golang.org/p/vCRCv4rt7s

re := regexp.MustCompile(`and|are`)
fmt.Printf("%q\n", re.Split("Dogs and Cats are Great", -1))
Run Code Online (Sandbox Code Playgroud)