Regular expression - how to match square bracket pairs in vim
phpcn_u15822017-05-16 16:41:46
0
2
967
It seems that I use \[ to match [, use ] to match]. I use \[*] to match the square bracket pair, but a\[*] cannot match the bracket pair with a in front (array a) , but using a\[ can match a and the left bracket after a. Why?
But are you sure you want to use *? Your "like" makes me have the urge to give you a tutorial on regular expressions...
[...] 是用来匹配字符类的,比如 [abd] 匹配 a, b 或者 d 中的任何一个。因为 [] 已经有这个意思了,所以要匹配到 [ 字符需要转义 [,要匹配 ] 的话原则上也是要转义的 ], but it does not need to be escaped when it does not cause ambiguity.
* 是一个量词,它表示前边那个字符(或者字符类、字符组 is a quantifier, which means that the previous character (or character class, character group) can appear anywhere Multiple times (0 times also counts).
My test result is
a[*]
可以匹配到a[]
。当然它不能匹配a[i]
.But are you sure you want to use
*
? Your "like" makes me have the urge to give you a tutorial on regular expressions...[...]
是用来匹配字符类
的,比如[abd]
匹配a
,b
或者d
中的任何一个。因为[]
已经有这个意思了,所以要匹配到[
字符需要转义[
,要匹配]
的话原则上也是要转义的]
, but it does not need to be escaped when it does not cause ambiguity.*
是一个量词
,它表示前边那个字符
(或者字符类
、字符组
is aquantifier
, which means that the previouscharacter
(orcharacter class
,character group
) can appear anywhere Multiple times (0 times also counts).