-1

我有类似的字符串

[any characters]{$\prime$}[any characters]$[any characters]{$\prime$}[any characters]$[any characters]

我想替换$\prime$$"The second one" 里面的那个被替换为 \prime 所以replace的输出是

[any characters]{$\prime$}[any characters]$[any characters]{\prime}[any characters]$[any characters]

如何使用 Reqex.Replace 做到这一点

这是我使用的代码

trannsformContent = Regex.Replace(trannsformContent, @"(\$)(?<cont>.*?)(\$)\\prime(\$)(?<cont1>.*?)(\$)", @"${cont}\prime{cont1}$", RegexOptions.Compiled | RegexOptions.Singleline | RegexOptions.IgnoreCase);
4

1 回答 1

0

我找到了解决方案:

trannsformContent = Regex.Replace(trannsformContent, @"\${1}(?<cont>.*?)\${1}\\prime\${1}(?<cont1>.*?)\${1}", @"$$${cont}\prime${cont1}$", RegexOptions.Compiled | RegexOptions.Singleline | RegexOptions.IgnoreCase);
于 2012-04-10T06:43:09.697 回答