public string regexDate(string str)
{
return Regex.Replace(str,"'(?<year>//d{4})-(?<month>//d{1,2})-(?<day>//d{1,2})'","To_Date('${year}-${month}-${day}','yyyy-mm-dd')",RegexOptions.Multiline);
<script type=text/JavaScript> alimama_pid="mm_10498610_623104_1064237"; alimama_titlecolor="0000FF"; alimama_descolor ="000000"; alimama_bgcolor="FFFFFF"; alimama_bordercolor="E6E6E6"; alimama_linkcolor="008000"; alimama_bottomcolor="FFFFFF"; alimama_anglesize="0"; alimama_bgpic="0"; alimama_icon="0"; alimama_sizecode="36"; alimama_width=336; alimama_height=280; alimama_type=2; </script> <script src="http://a.alimama.cn/inf.js" type=text/javascript></script>
}
有些时候我偶们希望在正则表达式的替换中对替换的字符换进行简单的处理,比如把所有的A依次替换为B1、B2、B3……这就需在替换时对字符串进行处理,其实这个很简单,用C#中的MatchEvaluator委托就可以了。简单的示例如下:
public static string ParseToHTML(string ubbString)
{
Regex rgx;
string htmlString = "";
MatchEvaluator me = new MatchEvaluator(AddOne);
rgx = new Regex(@"/[code/](.*?)/[//code/]");
htmlString = rgx.Replace(htmlString, me);
return htmlString;
}
public static string AddOne(Match m)
{
string code = m.Value.Substring(6, m.Value.Length - 13);
string codeString = @"<textarea name='code" + i + "' class='code_text'>" + code + "</textarea></div><br />";
i++;
return codeString;
}