我想创建一个表达式来捕获一些方括号前后的所有内容。
这样:
Test - ho-server-01[IWM]/Memory Usage
将捕获:
Test - ho-server-01
Memory Usage
再举几个例子:
Test - ho-server-01[IWM]/Memory Usage
IMWS Test - ho-server-01 [IWM]/Memory Usage
到目前为止我有这个([^[]*)
答案 0 :(得分:2)
答案 1 :(得分:1)
使用
(.*)\[[^\]\[]*\](.*)
见proof。
说明
--------------------------------------------------------------------------------
( group and capture to \1:
--------------------------------------------------------------------------------
.* any character except \n (0 or more times
(matching the most amount possible))
--------------------------------------------------------------------------------
) end of \1
--------------------------------------------------------------------------------
\[ '['
--------------------------------------------------------------------------------
[^\]\[]* any character except: '\]', '\[' (0 or
more times (matching the most amount
possible))
--------------------------------------------------------------------------------
\] ']'
--------------------------------------------------------------------------------
( group and capture to \2:
--------------------------------------------------------------------------------
.* any character except \n (0 or more times
(matching the most amount possible))
--------------------------------------------------------------------------------
) end of \2