开发者

Characters classes in ranges - vim

开发者 https://www.devze.com 2023-03-23 01:20 出处:网络
Given I have the following string: This is a test {{ string.string.string }}. And try to perform the following substitution:

Given I have the following string:

This is a test {{ string.string.string }}.

And try to perform the following substitution:

%s/{{ [\w\.]\+ }}/substitute/g

It will not work with the error: Pattern not found.

When I use:

%s/{{ [a-zA-Z\.]\+ }}/substitute/g
开发者_运维问答

It works.

Is there a way to use the meta-character-classes in ranges in VIM?


You can use:

  • A non capturing sub-expression, see :help E53 (you can use a capturing sub-expression as well, \(\), but the overhead of capturing is useless)

    %s/{{ \%(\w\|\.\)\+ }}/substitute/g
    
  • A sequence of optionally matched atoms - \%[], see :help E70

    %s/{{ \%[\w\.]\+ }}/substitute/g
    
0

精彩评论

暂无评论...
验证码 换一张
取 消