Google 工作表 REGEXREPLACE() 用自身替换文本

Google sheets REGEXREPLACE() replace text with itself

在 Google 表格中,我想替换以下文本:

The ANS consists of fibers that stimulate ((1smooth muscle)), ((2cardiac muscle)), and ((3glandular cells)).

以下文字:

The ANS consists of fibers that stimulate {{c1::smooth muscle}}, {{c2::cardiac muscle}}, and {{c3::glandular cells}}.

我知道如果我使用 =REGEXREPLACE(E3, "\(\([0-9]*", "{{c::") 我可以到达这里:

The ANS consists of fibers that stimulate {{c::smooth muscle)), {{c::cardiac muscle)), and {{c::glandular cells)).

但我不知道如何保留原始数字

Nvm,想通了。

在术语两边加上括号允许您在替换字符串中再次引用它。

例如,我的问题解决方案是这样的:

=REGEXREPLACE(E3, "\(\(([0-9]*)", "{{c::")

之所以有效,是因为像这样将 [0-9]* 放在括号中:([0-9]*) 允许它在我的替换字符串中被引用为 </code>。</p> <p>我假设如果我在后面的括号中有另一个短语,它就可以用 <code> 引用。

希望这对以后的人有所帮助。

第 1 轮:

搜索模式:(((\d)(.+)

替换:{{C$1::$2

第 2 轮:

搜索模式:))

替换:}}

我又试了一下,这一次就搞定了:

搜索模式:\(\((\d)(.+?)\b\)\)

替换:{{C::}}