<div style="word-break:break-all"><a href="http://www.92mp3.com/lrc/lrc.asp?ac=down&id=2650&gq=喜欢你(live91)" target=_blank>LRC歌词来自:http://www.92mp3.com/lrc/lrc.asp?ac=down&id=2650&gq=喜欢你(live91)</a></div>
需要的是用正则匹配得到http://www.92mp3.com/lrc/lrc.asp?ac=down&id=2650&gq=喜欢你(live91)上面的div是页面的一部分,我只想得到http://www.92mp3.com/lrc/lrc.asp?ac=down&id=2650&gq=喜欢你(live91)这个url其他的url要过滤掉。请问高手怎么写。

解决方案 »

  1.   

    http://topic.csdn.net/u/20080511/19/a5254391-d433-4842-9f29-f9e29e421628.html
    楼主参考,尝试着自己写一个吧。
      

  2.   

    http://www.92mp3.com/lrc/lrc.asp?ac=down&id=2650&gq=喜欢你(live91)
    除了这个之外的都过滤掉.这个不就是正则表达式了.把其中的用转义符号代替一下就不就行了.
      

  3.   

    string Regex("http://www.92mp3.com/lrc/lrc.asp?ac=down&id=2650&gq=喜欢你(live91)这个url");
    return Regex.Match(strUrl, Regex);
      

  4.   


    /*
    <div style="word-break:break-all"><a href="http://www.92mp3.com/lrc/lrc.asp?ac=down&id=2650&gq=喜欢你(live91)" target=_blank>LRC歌词来自:http://www.92mp3.com/lrc/lrc.asp?ac=down&id=2650&gq=喜欢你(live91)</a></div>
    需要的是用正则匹配得到http://www.92mp3.com/lrc/lrc.asp?ac=down&id=2650&gq=喜欢你(live91)上面的div是页面的一部分,我只想得到http://www.92mp3.com/lrc/lrc.asp?ac=down&id=2650&gq=喜欢你(live91)这个url其他的url要过滤掉。请问高手怎么写。
    */import java.util.regex.Matcher;
    import java.util.regex.Pattern;public class Test{
    public static void main(String[] args){
    String divContent = "<div style=\"word-break:break-all\"><a href=\"http://www.92mp3.com/lrc/lrc.asp?ac=down&id=2650&gq=喜欢你(live91)\" target=_blank>LRC歌词来自:http://www.92mp3.com/lrc/lrc.asp?ac=down&id=2650&gq=喜欢你(live91)</a></div>";

    String regex = "href=\"([^\"]+)"; Pattern pattern = Pattern.compile(regex);
    Matcher matcher = pattern.matcher(divContent); if(matcher.find()){
    System.out.println(matcher.group(1));
    }
    }
    }