Remove text between [" "]
I will have to process chunks of text which may contain ["text between square brackets and double quotes"]. The idea is to remove that text, including the quotes and brackets, and keeping the rest.
My current regex is as follows:
This works fine on the following:
Hello ["remove this"] world ["remove this too"] !
Hello world !
But it falls apart when I enter a quote inside [" "]:
Hello ["remo"ve this"] world ["remove this too"] !
In this case, the second [" "] is handles properly, but the first one stays put. What am I doing wrong?
Nothing. Your [^"] doesn't allow any quotes inside, so if there are any the match fails.
Swap it for an ungreedy .*?
That did the trick. Awesome!