Do you need to be able to strip out \n
, \r\n
, or both?
This should do the job:
/(^|^.|[^{].|.[^\]])\r?\n/gm
And would require that you place $1
at the beginning of your replacement string.
To answer your question about why /[^\{\]]\n/
is wrong, this regex equates to: "match any character that is neither {
nor ]
", followed by \n
, so this incorrectly fail to match the following:
here's a square]\n
see the following{\n
You're also missing the g
flag at the end, but you may have noticed that.