Vim 正则表达式捕获组 [bau ->byau : ceu ->cyeu] [英] Vim Regex Capture Groups [bau -> byau : ceu -> cyeu]
本文介绍了Vim 正则表达式捕获组 [bau ->byau : ceu ->cyeu]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个单词列表:
bau
ceu
diu
fou
gau
我想把那个列表变成:
byau
cyeu
dyiu
fyou
gyau
我尝试命令失败:
:%s/(w)(ww)/1y2/g
鉴于这不起作用,我需要更改什么才能使正则表达式捕获组在 Vim 中工作?
Given that this doesn't work, what do I have to change to make the regex capture groups work in Vim?
推荐答案
解决这个问题的一种方法是确保模式用转义括号括起来:
One way to fix this is by ensuring the pattern is enclosed by escaped parentheses:
:%s/(w)(ww)/1y2/g
使用 v
稍微短一些(和更多 magic-al),这意味着在它之后的模式中除了 '0'- 之外的所有 ASCII 字符'9'
, 'a'-'z'
, 'A'-'Z'
和 '_'
有一个特殊含义:
Slightly shorter (and more magic-al) is to use v
, meaning that in the pattern after it all ASCII characters except '0'-'9'
, 'a'-'z'
, 'A'-'Z'
and '_'
have a special meaning:
:%s/v(w)(ww)/1y2/g
见:
查看全文