简体   繁体   English

在Vim中的正则表达式中将句点添加到匹配的模式中

[英]Add period into matched pattern in regex in vim

I'm trying to replace 我正在尝试更换

underline{someword} 下划线{someword}

with

underline{someword.} 下划线{someword。}

in Vim. 在Vim中。

I've tried 我试过了

:%s/underline{\w*}/underline{$1\.}/g

but it changes the matched patterns to 但是它将匹配的模式更改为

underline{$1.} 下划线{$ 1。}

Why? 为什么? How do I fix this? 我该如何解决?

您忘记了捕获小组

:%s/underline{\(\w*\)}/underline{\1\.}/g

You can use grouping: 您可以使用分组:

:%s/\(underline{\w*\)}/\1\.}/g

Here \\(...\\) is used for grouping the match. 这里\\(...\\)用于对匹配进行分组。

使用经常被低估的\\zs\\ze

:%s/\munderline{\w*\zs\ze}/./g

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM