字符类范围 - Vim

11

假设我有以下字符串:

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

并尝试执行以下替换:

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

会出现错误:未找到模式。

当我使用以下代码时:

%s/{{ [a-zA-Z\.]\+ }}/substitute/g

它起作用了。

在VIM中是否有一种方法可以在范围内使用元字符类?

1个回答

9

您可以使用:

  • 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
    

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接