Ber*_*nnF 9 regex vim special-characters
鉴于我有以下字符串:
This is a test {{ string.string.string }}.
Run Code Online (Sandbox Code Playgroud)
并尝试执行以下替换:
%s/{{ [\w\.]\+ }}/substitute/g
Run Code Online (Sandbox Code Playgroud)
它不适用于错误:找不到模式.
我用的时候:
%s/{{ [a-zA-Z\.]\+ }}/substitute/g
Run Code Online (Sandbox Code Playgroud)
有用.
有没有办法在VIM中使用范围中的元字符类?
您可以使用:
非捕获子表达式,请参阅:help E53(您也可以使用捕获子表达式\(\),但捕获的开销是无用的)
%s/{{ \%(\w\|\.\)\+ }}/substitute/g
Run Code Online (Sandbox Code Playgroud)一系列任意匹配的原子 - \%[]见:help E70
%s/{{ \%[\w\.]\+ }}/substitute/g
Run Code Online (Sandbox Code Playgroud)