利用 Regexp 对象的 Split 方法实现正则切割字符串

简单的例子:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
package main
import (
"fmt"
"regexp"
)
func main(){
spaceRe, _ := regexp.Compile(`\s+`)
s := "a b c d e"
ss := spaceRe.Split(s, -1)
fmt.Println(len(ss), ss)
}
输出:
15 [a b c d e]
参考
本文网址: https://py.youbbs.org/topic/157.html 转摘请注明来源