asp.net 正则匹配链接

发布时间:2013-09-19 11:33:46来源:阅读(1305)

    [code=C#]
    string   s   =   "...........";  
       
    Regex   re   =   new   Regex(@"]*href=(""(?[^""]*)""|'(?[^']*)'|(?[^\s>]*))[^>]*>(?.*?)",   RegexOptions.IgnoreCase   |   RegexOptions.Singleline);  
    Match   m   =   re.Match(s);  
    if   (m.Success)  
    {  
    string   link   =   m.Groups["href"].Value;  
    string   text   =   Regex.Replace(m.Groups["text"].Value,"<[^>]*>","");  
    Console.WriteLine("link:{0}\ntext:{1}",   link,   text);  
    }
    [/code]

    string interStr=@"(?<=]*>).*(?=)";//提取之间的字串
    Regex myReg=new Regex(interStr);
    Match myMatch=myReg.Match(inputStr);
    if(myMatch.Success)
    {

    string finalStr=myMatch.Value.ToString();//获取之间的字串
    string finalStr2=Regex.Replace(finalStr,"]*>|\\.|mp3","");//将字串中的<>以及<>里的字母,还有.mp3替换掉
    Console.WriteLine(finalStr2);//打印最终符合要求的文字

    }
    else
    {
    Console.WriteLine("No!");
    }

关键字正则