给出以下html文本片段
<th>Member name:</th>
<td>$$FULLNAME$$</td>
<th>Club:</th>
<td>$$ClubName$$</td>
<th>Business Category:</th>
<td>$$SubCategory$$</td>
我正在尝试更换所有令牌,例如$$FULLNAME$$
使用C#变为$$fullname$$
,输出应为
<th>Member name:</th>
<td>$$fullname$$</td>
<th>Club:</th>
<td>$$clubname$$</td>
<th>Business Category:</th>
<td>$$subcategory$$</td>
由于\L
没有将匹配项转换为小写
public static string TokenReplacer(string value)
{
var pattern = Regex.Escape("$$") + "(.*?)" + Regex.Escape("$$");
var regex = new Regex(pattern);
return regex.Replace(value, Regex.Unescape("$$$$") + @"\L$1" + Regex.Unescape("$$$$"));
}
答案 0 :(得分:3)
var output = Regex.Replace(input, @"\$\$.+?\$\$", m => m.Value.ToLower());