如何更换
convert(varchar,CREATED_ON,106) => to_char(CREATED_ON, 'dd/mon/yyyy')
类似于以下代码
string ss = Regex.Replace("convert(varchar,CREATED_ON,106)", @"convert(varchar,^[a-zA-Z][a-zA-Z0-9]*$,106)", "to_char(CREATED_ON, 'dd/mon/yyyy')", RegexOptions.IgnoreCase);
我该怎么做?
答案 0 :(得分:0)
这样的事情?
class Program
{
static void Main(string[] args)
{
Regex reg = new Regex(@"convert\(\s?varchar\s?,(.*?)\s?,\s?106\s?\)",RegexOptions.IgnoreCase);
string original = "convert(varchar,CREATED_ON,106)";
string replaced = reg.Replace(original, "to_char($1, 'dd/mon/yyyy')");
Console.WriteLine(replaced);
}
}
或不使用静态方法创建正则表达式:
string ss = Regex.Replace(original, @"convert\(\s?varchar\s?,(.*?)\s?,\s?106\s?\)", "to_char($1, 'dd/mon/yyyy')", RegexOptions.IgnoreCase);
$ 1将被第一组(。*?)中的whats取代。