问题
I want to make a negated character class to match a square bracket tag like this [square bracket tag]. The problem is, the ] character ends the character class!
I tried
\[[^\]]+]
but I get a syntax error when I run it. (This is in the find and replace regex engine which is slightly different than the standard .NET engine fyi).
回答1:
You forgot to escape the final end bracket:
\[[^\]]+\]
回答2:
The first example in msdn uses \\ for escaping the \ which then escapes the .. So you should do something like \\[[^\\]]+\\] and also as Damien_The_Unbeliever said you haven't closed the final bracket.
回答3:
I definitely expected escaping with "\" but it didn't work for me (grep@MacOS) but this:
[^]]
did the job.
Just place ] as the first character in class.
I actually used something like:
[^]?[]
来源:https://stackoverflow.com/questions/11427563/visual-studio-find-and-replace-right-square-bracket-in-character-class