What are the differences between the regular expressions used to replace content in vim and those in other programming languages?
I only know that the first matched group in vim is \1
, which is equivalent to $1
in js.
元字符 含义说明
. 匹配任意字符
\[abc\] 匹配放括号中的任意字符,也可以表示范围,例如[a-z0-9]
\[^abc\] 匹配除方括号中字符的任意其他字符
\d 匹配阿拉伯数字,等同于[0-9]
\D 匹配除阿拉伯数字之外的其他字符,等同于[^0-9]
\x 匹配十六进制数字,等同于[0-9A-Fa-f]
\X 匹配十六进制之外的任意字符,等同于[^0-9A-Fa-f]
\w 匹配单词字母,等同于[0-9A-Za-z_]
\W 匹配单词字母之外的任意字符,等同于[^0-9A-Za-z_]
\t 匹配<Tab\>字符
\s 匹配空白字符,等同于[ \t]
\S 匹配非空白字符,等同于[^ \t]
\* 匹配0-任意个
\+ 匹配1-任意个
\? 匹配0-1个
\{n,m\} 匹配n-m个
\{n,\} 匹配n-任意个
\{,m\} 匹配0-m个
& 匹配行尾
^ 匹配行首
\< 匹配单词词首
:help pattern-overview
Or read the Chinese version of the document https://github.com/vimcn/vimcdoc/blob/master/doc/pattern.txt