如何用正则表达式进行这样的替换
对于 "abk{fdafdljkla;kjke}fdafdafdasf "如何替换成
"abk{{}fdafdljkla;kjke{}}fdafdafdasf "
就是对于{,替换成{{}, 对于},替换成{}}。用正则如何做?
------解决方案--------------------try
string yourStr = "abk{fdafdljkla;kjke}fdafdafdasf ";
string resultStr = Regex.Replace(yourStr, @ "\{|\} ", new MatchEvaluator(expReplace));
private string expReplace(Match m)
{
return m.Value == "{ " ? m.Value.Replace( "{ ", "{{} ") : m.Value.Replace( "} ", "{}} ");
}