前端之家收集整理的这篇文章主要介绍了
Go语言正则表达式,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
packagemain
import(
"fmt"
"regexp"
)
funcmain(){
//regularexpressionpattern
regE:=regexp.MustCompile("/oid/([\\d]+)/")
//simulateasearch
//firstconvertstringtobyteforFind()function
searchByte:=[]byte("/oid/1/")
matchSlice:=regE.Find(searchByte)
fmt.Printf("%s\n",matchSlice)//iffound,returnleftmostmatch,without'abc'
matchSlice2:=regE.FindAll(searchByte,500)
fmt.Printf("%s\n",matchSlice2)//iffound,returnallsuccessivematches
oid:=regE.NumSubexp()
fmt.Printf("OIDis%d\n",oid)
//thisishowtosearchbystring
matchSlice3:=regE.FindAllString(string(searchByte),-1)
fmt.Printf("%s\n",matchSlice3)//iffound,returnallsuccessivematches
}
原文链接:https://www.f2er.com/regex/360180.html