Visual Studio find and replace right square bracket ] in character class

匆匆过客 提交于 2020-01-02 01:20:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!