![](/img/trans.png)
[英]Vim: Replace regular expression match on a line with another regular expression match from same line
[英]Regular expression to replace a value with one from the same line
我需要用每行逗号后面的值替换单词 'foo' - 例如'foo'
变为'bar1'
。 output 应如下所示: this.load.image('bar1', bar1);
this.load.image('foo', bar1);
this.load.image('foo', bar2);
this.load.image('foo', bar3);
...
这怎么能用正则表达式来完成?
搜索:
\('[^']+',\s*([^\)]+)\);\s*$
替代品
('$1', $1);
根据文本编辑器,它可能是\1
而不是$1
。 我使用 sublime,所以我不确定使用的是哪种风格与代码。
解释:
\( - Match (
'[^']+', - Match ', then all text until next ', next ' and the comma
\s* - Zero or more spaces
([^\)]+) - Capture group everything up to the next ). the group is important
\);\s*$ - Closing ); then any number of spaces and end of line.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.