我想要一个与括号和其他文本之间的''字符匹配的正则表达式:
[Hello World]
^
我已经做到了这一点:
\[.* .*\]
但不幸的是,这也与此相符:
[HelloWorld] [HelloWorld]
^
有没有办法排除这种情况?
答案 0 :(得分:3)
不使用任意数量的通配符(.
)字符,而是使用任意数量的非括号字符:
\[[^\]\[]* [^\]\[]*\]
最初看起来很不清楚,但它会像这样崩溃:
\[ first bracket
[^ exclusion class:
\]\[ exclude brackets
]* end exclusion; any amount
space
[^ exclusion class:
\]\[ exclude brackets
]* end exclusion; any amount
\] final bracket
答案 1 :(得分:1)
尝试这样的事情:
\[([^\]*)\] \[([^\]*)\]
答案 2 :(得分:0)
如何使用单词边界?
\[.*\b \b.*\]
答案 3 :(得分:0)
您可以使用此
\[[^[]]* [^[]]*\]
答案 4 :(得分:0)
你可以使用它(在查找模式的末尾有一个空格):
find: (\[.*?)
replace: \1
(在记事本++ 6.3.2上测试)