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);
}
有些时候我偶们希望在正则表达式的替换中对替换的字符换进行简单的处理,比如把所有的A依次替换为B1、B2、B3……这就需在替换时对字符串进行处理,其实这个很简单,用C#中的MatchEvaluator委托就可以了。简单的示例如下:
引用内容:
private static int i = 0;
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;
}
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;
}