英文:
Golang Regexp Reference within MustCompile (Find repeating character)
问题
我在处理Go的正则表达式时遇到了困难。它似乎与其他语言不同,有人可以帮我吗?
目标:我想使用MustCompile在字符串中找到所有重复的字符。
例如:在字符串"APPLE"中,P是重复的。
我尝试了以下代码,但完全没有起作用:
re := regexp.MustCompile("(\w)\${1}\+")
基本上,我想要的是:
([A-Za-z])\1+
有人可以告诉我我做错了什么吗?
以下是示例代码:
https://play.golang.org/p/DeuaIva968
英文:
I am having a hard time with Go's regex. It seems it's different than other language, can someone help me on this.
Obj. I want MustCompile to find all repeated characters in the string.
APPLE (where P's repeating)
re := regexp.MustCompile("(\\w)\${1}\\+")
Above is what I have tried but didn't work at all. Basically I wanted to do:
([A-Za-z])+
Can someone tell me what I am doing wrong?
Example below:
答案1
得分: 2
显然,由于效率问题,Golang不支持回溯引用。:(
谢谢大家的帮助。
英文:
Apparently Golang doesn't supposed back referencing due to efficiency.
Thank you everyone for your help.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论