string t5 = "01/01/01 16:10:01";
string p5 = @"(d+)/(d+)/(d+) (d+):(d+):(d+)";
Match m5 = Regex.Match(t5, p5);
改变目录(仅适用于Windows平台)
string t6 = @"C:Documents and Settingsuser1Desktop";
string r6 = Regex.Replace(t6,@"\user1\", @"\user2\");
扩展16位转义符
string t7 = "%41"; // capital A
string p7 = "%([0-9A-Fa-f][0-9A-Fa-f])";
string r7 = Regex.Replace(t7, p7, HexConvert);
删除C语言中的注释(有待完善)
string t8 = @"
/*
* 传统风格的注释
*/
";
string p8 = @"
/* # 匹配注释开始的定界符
.*? # 匹配注释
*/ # 匹配注释结束定界符
";
string r8 = Regex.Replace(t8, p8, "", "xs");
删除字符串中开始和结束处的空格
string t9a = " leading";
string p9a = @"^s+";
string r9a = Regex.Replace(t9a, p9a, "");
string t9b = "trailing ";
string p9b = @"s+?$";
string r9b = Regex.Replace(t9b, p9b, "");
在字符后添加字符n,使之成为真正的新行
string t10 = @"ntestn";
string r10 = Regex.Replace(t10, @"\n", "n");
转换IP地址
string t11 = "55.54.53.52";
string p11 = "^" +
@"([01]?dd|2[0-4]d|25[0-5])." +
@"([01]?dd|2[0-4]d|25[0-5])." +
@"([01]?dd|2[0-4]d|25[0-5])." +
@"([01]?dd|2[0-4]d|25[0-5])" +
"?$";
Match m11 = Regex.Match(t11, p11);
删除文件名包含的路径
string t12 = @"c:file.txt";
string p12 = @"^.*\";
string r12 = Regex.Replace(t12, p12, "");
联接多行字符串中的行
string t13 = @"this is a split line";
string p13 = @"s*r?ns*";
string r13 = Regex.R