Any (format) strings in a file (C or C++ code), even containing escaped characters or newlines are needed to be found by a tool written in Go. Examples:
..."foo"...
...`foo:"foo"`...
..."foo
foo"...
..."foo\r\nfoo"...
...`foo"foo-
lish`
The C/C++ parsing is allowed to be done also in comments or deactivated code, so no need to exclude that parts.
I succeeded with
/(["'`])(?:(?=(\?))\2.)*?\1/gms
on https://regex101.com/r/FDhldb/1 searching for a solution.
Unfortunately this does not compile in Go:
const (
patFmtString = `(?Us)(["'])(?:(?=(\\?))\2.)*?\1`
)
var (
matchFmtString = regexp.MustCompile(patFmtString)
)
Even the simplified pattern (?Us)(["'])(?:(\\?).)*?\1
delivers "error parsing regexp: invalid escape sequence: \1
".
How do I correctly implement that in Go, hopefully running also fast?