regex – Go regular expression
is there a go regular expression that matches the repeated consecutive substring in a string?
for example:
if input = “ababcdefghfghfghrrrrrm”
the regular expression must match the following cases:
abab
fghfghfgh
rrrrr
I tried this regex (\w+)\1+
but I got an error messge in vscode. any equivelent regex in go?
This is the error message:error parsing regexp: invalid escape sequence: \1
(SA1000)
when I ran the code, it also gives error:
panic: regexp: Compile((\w+)\1+
): error parsing regexp: invalid escape sequence: \1
goroutine 1 [running]:
regexp.MustCompile({0x4cfcc4, 0x8})
/home/linuxbrew/.linuxbrew/Cellar/go/1.22.1/libexec/src/regexp/regexp.go:317 +0xb4
art/functions.RepeatedSubstrings({0x7ffe5b7eec56, 0x16})
Read more here: Source link