日期:2014-05-17 浏览次数:20708 次
string format = @"https://www.(\w+).com/ABC/(.+)?";
Regex g = new Regex(format);
string mystr = @"https://www.baidu.com/AB/a.aspx";
if (g.IsMatch(mystr))
{
Console.WriteLine("yes");
}
else
{
string t = @"https://www.(\w+).com";
Regex g2 = new Regex(t);
string url= g2.Match(mystr).Groups[0].Value;
Console.WriteLine("no");
Console.WriteLine(url);
int index = mystr.IndexOf(url)+url.Length;
string newstr= mystr.Insert(index, @"/ABC");
Console.WriteLine(newstr);
}
Console.Read();
void Main()
{
string[] ary= {
"https://www.domain.com/ABC/edit.aspx&..",
"https://www.domain.com/user/abc.aspx&... ",
"https://www.domain.com/ABC.html"
};
foreach(var str in ary)
Console.WriteLine("{0}\t{1}",str,Regex.Re