Go语言正则表达式
发布时间:2020-12-14 01:11:39 所属栏目:百科 来源:网络整理
导读:packagemainimport("fmt""regexp")funcmain(){//regularexpressionpatternregE:=regexp.MustCompile("/oid/([d]+)/")//simulateasearch//firstconvertstringtobyteforFind()functionsearchByte:=[]byte("/oid/1/")matchSlice:=regE.Find(searchByte)fmt.Pr
packagemain import( "fmt" "regexp" ) funcmain(){ //regularexpressionpattern regE:=regexp.MustCompile("/oid/([d]+)/") //simulateasearch //firstconvertstringtobyteforFind()function searchByte:=[]byte("/oid/1/") matchSlice:=regE.Find(searchByte) fmt.Printf("%sn",matchSlice)//iffound,returnleftmostmatch,without'abc' matchSlice2:=regE.FindAll(searchByte,500) fmt.Printf("%sn",matchSlice2)//iffound,returnallsuccessivematches oid:=regE.NumSubexp() fmt.Printf("OIDis%dn",oid) //thisishowtosearchbystring matchSlice3:=regE.FindAllString(string(searchByte),-1) fmt.Printf("%sn",matchSlice3)//iffound,returnallsuccessivematches } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |