有个新手要去,并注意到了这一点:
package main
import (
"fmt"
"regexp"
)
func main() {
re,_ := regexp.Compile("\\d+")
re2,_ := regexp.Compile("\\d*")
str := "There were 964 people in the crowd."
val := re.FindAllString(str,-1)
val2 := re2.FindAllString(str, -1)
fmt.Println("First regex: ")
fmt.Println(re)
fmt.Println("Captured: " + val[0])
fmt.Println("\nSecond regex: ")
fmt.Println(re2)
fmt.Println("Captured: " + val2[0])
}
哪个产量:
First regex:
\d+
Captured: 964
Second regex:
\d*
Captured:
'*'量词有什么用?为什么+捕获但*不能捕获。感谢您理解为什么会有这种帮助。 RE2正则表达式实现的参考信息在这里:https://github.com/google/re2/wiki/Syntax 建议支持*量词-那么我在做什么错了?
谢谢!