I'm trying to match to expresions contained within [%___%] in a string, before // (comments) excluding // that are in quotations (inside a string)
so for example
[%tag%] = "a" + "//" + [%tag2%]; //[%tag3%]
should match [%tag%] and [%tag2%]
The closest I can get is ^(?:(?:\[%([^%\]\[]*)%\])|[^"]|"[^"]*")*?(?://)
So the problems I'm having are that this doesn't match any strings which don't end in //
In fact, it aggregates lines until it can conclude in one that contains //
I've tried to remedy this problem with ?.*?$ at the end, to signify that // is not necessary and to go to the first endline, but it doesn't really work.
And Secondly, it only captures the second tag. This isn't because of the "//" since even with [%1%] [%2%] it won't capture the first
I'm using C# and Regex.Matches with the RegexOptions.Multiline option and this is my escaped string
"^(?:(?:\\[%([^%\\]\\[]*)%\\])|[^\"]|\"[^\"]*\")*?(?://)"