【发布时间】:2014-01-08 20:52:54
【问题描述】:
我想在 .NET 中转义正则表达式替换命令中的替换部分:
public static string GetPriceMessage(string data, string price)
{
var repl = "This is a $1 priced at " + price + " suitable for $2.";
return Regex.Replace(data, "item_name: ([^;]+); suitable: ([^;]+)", repl);
}
var price = "$15/item";
var data = "item_name: Puzzle; suitable: all ages";
GetPriceMessage(data, price)
我想确保 price 被逐字替换。 Regex.Escape 不起作用。
【问题讨论】:
标签: c# .net regex replace substitution