stringsregexp
strings.Count
1
strings.Count("abcdassa", "a")

结果是 3

as
1
2
3
4
5
6
7
8
9
10
11
12
13
package main

import (
    "fmt"
    "regexp"
)

func main() {
    orExp := regexp.MustCompile("a|s")

    matches := orExp.FindAllStringIndex("abcdassa", -1)
    fmt.Println(len(matches))
}

结果会输出 5

本文网址: https://golangnote.com/topic/270.html 转摘请注明来源