C# 在同一个正则表达式上同时添加两个Replace-执行两个不同的操作
我的问题是,例如,当我添加一个更像需要替换的点时。然后它会出现以下错误: 无法从字符串转换为System.stringComparison 如果我这样评论最后一次替换。这样就没有问题了,但只有在我的正则表达式中添加了额外的替换项时才会出现这种情况C# 在同一个正则表达式上同时添加两个Replace-执行两个不同的操作,c#,regex,C#,Regex,我的问题是,例如,当我添加一个更像需要替换的点时。然后它会出现以下错误: 无法从字符串转换为System.stringComparison 如果我这样评论最后一次替换。这样就没有问题了,但只有在我的正则表达式中添加了额外的替换项时才会出现这种情况 text = Regex.Replace(text, @"{(?s)(.*){medlem}}.*{{medlemstop}}", "<img src=\"https://aaaa.azureedge.net/imagesfiles
text = Regex.Replace(text, @"{(?s)(.*){medlem}}.*{{medlemstop}}",
"<img src=\"https://aaaa.azureedge.net/imagesfiles/hello.png\" class=\"img-responsive\" alt=\"hello world\">")
.Replace(text, @"{(?s)(.*){pay}}.*{{paystop}}", "ERROR HERE!!!");
我也尝试过这样做:
如果只有Regex.Replace返回Regex,我们将能够链替换:Replace…Replace…Replace。。。;
但是,唉!Replace返回字符串,因此不能对其字符串使用正则表达式方法。这些选择包括:
嵌套调用:
连续呼叫:
Replace返回一个字符串。不能执行Regex.Replace.Replace并使用Regextext=Regex.ReplaceRegex.Replacesource、pattern、value、anotherPattern、anotherValue;谢谢你的回答!我会尽量让米格明白这一点:祝你好运!
text = Regex.Replace(
Regex.Replace(
text,
@"{(?s)(.*){medlem}}.*{{medlemstop}}",
"<img src=\"https://aaaa.azureedge.net/imagesfiles/hello.png\" class=\"img-responsive\" alt=\"hello world\">"),
@"{(?s)(.*){pay}}.*{{paystop}}",
"ERROR HERE!!!");
text = Regex.Replace(
text,
@"{(?s)(.*){medlem}}.*{{medlemstop}}",
"<img src=\"https://aaaa.azureedge.net/imagesfiles/hello.png\" class=\"img-responsive\" alt=\"hello world\">");
text = Regex.Replace(
text,
@"{(?s)(.*){pay}}.*{{paystop}}",
"ERROR HERE!!!");