62,025
社区成员
发帖
与我相关
我的任务
分享
string subjectString = "<a href=\"http://www.aabb.net/cc/dddd/1234.html\"> ";
string resultString = null;
try
{
subjectString = subjectString.Replace("cc","china-cc");
resultString = Regex.Replace(subjectString, @"(?<first>\d+)", @"e-${first}");
}
catch (ArgumentException ex)
{
// Syntax error in the regular expression
}
string test = "<a href=\"http://www.aabb.net/cc/dddd/123.html\"> ";
Regex reg = new Regex(@"(?i)<a\s+href=""http://www.aabb.net/cc/dddd/(\d+).html"">");
string result = reg.Replace(test, "<a href=\"http://www.aabb.net/china-cc/dddd/e-$1.html\">");
using System;
using System.Collections;
using System.Text.RegularExpressions;
public class MyClass
{
public static void Main()
{
string str_1="sHjhgsdKkjhLjk";
Console.WriteLine(str_1+"\n");
Console.WriteLine(Regex.Replace(str_1,"[A-Z]",new MatchEvaluator(Replace)));
//new MatchEvaluator(Replace)用委托,对匹配的字符处理
RL();
}
public static string Replace(Match m)//
{
return " "+m.Value;
}
#region Helper methods
private static void WL(object text, params object[] args)
{
Console.WriteLine(text.ToString(), args);
}
private static void RL()
{
Console.ReadLine();
}
private static void Break()
{
System.Diagnostics.Debugger.Break();
}
#endregion
}