草庐IT

REGEX_EXTRACT_ALL

全部标签

regex - 转到正则表达式以匹配带有括号的标签

我想使用正则表达式包获取括号内所有标签的索引。str:="[tag=blue]Hello[tag2=red,tag3=blue]Good"rg:=regexp.MustCompile(`(?:^|\W)\[([\w-]+)=([\w-]+)\]`)rgi:=fmtRegex.FindAllStringIndex(str,-1)fmt.Println(rgi)//Wantindexfor://[tag=blue],[tag2=red,tag3=blue]正则表达式需要返回[tag=blue]、[tag2=red,tag3=blue]的索引但它只返回[tag=blue]。如何修复此正则表达

regex - 使用 golang 和 regexp 摆脱外部标签?

我正在使用goalng做一些模板,并想摆脱外部标签。如下所示:input:=`aaa{{4567}}111220aaabbb{{12345}}amrambler`我想获取字符串。它省略了标签"",""。只保留它们之间的内容,"{{4567}}"和"{{12345}}"str=`aaa{{4567}}aaabbb{{12345}}amrambler`提前致谢! 最佳答案 您可以使用以下方法获得所需的输出。packagemainimport("fmt""regexp")funcmain(){re:=regexp.MustCompile(

regex - FindStringSubmatch 的 Golang 正则表达式问题

我试图使用正则表达式与or运算符进行一些模式匹配,但我得到了一些奇怪的结果。除了要点之外,我已经删除了所有内容以显示我的结果存在问题。这是我的代码:主要包import"fmt"import"regexp"funcmain(){authRegexp:=regexp.MustCompile("^token=(llll|(.+))$")matches:=authRegexp.FindStringSubmatch("token=llll")fmt.Println("MATCHES",matches,len(matches))//MATCHES[token=llllllll]3}网址:http:

regex - 捕获两个大括号之间的所有数据

尝试读取两个大括号内的所有数据。我怀疑我的正则表达式失败是因为它无法匹配换行符。链接到goplayground中的源代码:http://play.golang.org/p/uNjd01CL8Zpackagemainimport("fmt""regexp")funcmain(){x:=`lease{interface"eth0";fixed-address10.11.0.1;optionsubnet-mask255.255.0.0;}lease{interface"eth0";fixed-address10.11.0.2;optionsubnet-mask255.255.0.0;}lea

regex - Goa 包的类型断言 (uuid.UUID)

我正在测试Goa对于一个API。我想使用uuid作为ID数据类型。我在controller.go中修改了以下函数://Showrunstheshowaction.func(c*PersonnelController)Show(ctx*app.ShowPersonnelContext)error{//v4UUIDvalidateregexvarvalidate=`^[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[8|9|aA|bB][a-f0-9]{3}-[a-f0-9]{12}$`uuidValidator:=regexp.MustCompile(valid

regex - golang 如何使用正则表达式将字符串拆分为包含分隔符的 slice

我想将一个字符串拆分成一个片段,但想保留分隔符。有没有办法在golang中做到这一点?例如输入:"Hello!It's,a?beautiful$day*(todayandtomorrow).输出:[Hello|!|It's|,|a|?|beautiful|$|day|*|(|today|and|tomorrow|)|.]其中|代表元素的分离。有人可以帮忙吗? 最佳答案 您可以通过创建一个匹配单词或您的特殊字符之一的正则表达式来做到这一点。我不确切知道你的规则是什么,但考虑到输入和所需的输出,这是可行的:[A-Za-z']+|[*?(

go - 使用 golang channel 。获取 "all goroutines are asleep - deadlock!"

我目前正在研究goroutines、channels和sync.WaitGroup。我知道waitgroup用于根据天气等待所有go例程完成wg.Done()已被调用足够多次以减少wg.Add()中设置的值。我写了一小段代码来尝试在golangPlayground上测试这个。显示如下varchannelchanintvarwgsync.WaitGroupfuncmain(){channel:=make(chanint)mynums:=[]int{1,2,3,4,5,6,7,8,9}wg.Add(1)goaddStuff(mynums)wg.Wait()close(channel)rec

mongodb - mgo collection.Find(nil).All(&users) 不工作

我有下一个问题..我无法从我的mongo数据库(在docker容器中运行)中获取所有记录,这是我非常简单的代码:typeUserstruct{Emailstring`json:"email"bson:"email"`Passstring`json:"pass"bson:"pass"`}session:=dbConnect()collection:=session.DB("my_db").C("users")varusers[]Usererr:=collection.Find(nil).All(&users)iferr!=nil{log.Fatal("Mongocollectionfin

regex - 在 ReplaceAllStringFunc 回调中获取组值

我试图用字符串中确定的数字范围用随机数替换字符串packagemainimport("fmt""math/rand""regexp""strconv")funcreplaceFunc(sstring)string{groups:=//??Howdoigetthecurrentmachgroupsreturnrand.Intn(groups[2]-groups[1])+groups[1]}funcmain(){rand.Seed(time.Now().Unix())repl:="1,101,501,121,21,3"repl=regexp.MustCompile("(\\d+),(\\d

regex - guid 的正则表达式

我在使用正则表达式时遇到一些问题。Error:Invalidoperationre:=regexp.MustCompile("(([a-f0-9]+\-)+[a-f0-9]+)\/(.*?)\/(.*?);version=(\d*)")match:=re.FindStringSubmatch(hex.EncodeToString([]byte(href)))fmt.Println(match)我要匹配的测试字符串是/data/1221a7f47-84c1-445e-a615-ff82d92e2eaa/article/jane;version=1493756861347/data/122