How can I match any duplicate character with regexp?

I need to combine any character that repeats twice, for example:

"abccdeff"

Must match "cc" and "ff". In any other regex syntax, let me use Javascript as a quick example, I could do:

var str = "abccdeff";
var r = /([a-z]{1})\1/g
console.log(str.match(r))

What returns

[ 'cc', 'ff' ]

But Regexp Go does not seem to allow this. Is it possible to do this in Go?

+4
source share
1 answer

Since backreference is not supported by re2 , you will need:

+5
source

Source: https://habr.com/ru/post/1618714/


All Articles