VSCode 正则表达式查找 &替换子匹配数学? [英] VSCode regex find & replace submatch math?
本文介绍了VSCode 正则表达式查找 &替换子匹配数学?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
%s@{fileID: \(213[0-9]*\)@\='{fileID: '.(submatch(1)-1900)@
我在 vim 中使用这个正则表达式搜索和替换命令从每个匹配的 id 中减去一个常量.
I am using this regex search and replace command in vim to subtract a constant from each matching id.
我可以在 VSCode 中进行正则表达式查找,但是如何引用 submatch
进行数学运算&代替?submatch(1)
在 VSCode 中不起作用?
I can do the regex find in VSCode but how can I reference the submatch
for maths & replace? submatch(1)
does not work in VSCode?
谢谢.
推荐答案
给定 (foobar)
的正则表达式,您可以使用 $1
引用第一组,依此类推如果您在替换输入字段中有更多组.
Given a regular expression of (foobar)
you can reference the first group using $1
and so on if you have more groups in the replace input field.
这篇关于VSCode 正则表达式查找 &替换子匹配数学?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文