日期:2014-05-20  浏览次数:20797 次

谁帮我写一个正则表达式。。谢谢。。。
下面是script 里面的 内容 我想得到 
HTML code
"key":1,"title":"\u7ec5\u58eb\u7684\u54c1\u683c01","url":"http:\/\/www.letv.com\/ptv\/pplay\/77505\/1.html",
这条内容,里面的 1 和 url 后面的 http 
HTML code

<script type="text/javascript">

    var LISTCACHE =[

        {
            "key":1,"title":"\u7ec5\u58eb\u7684\u54c1\u683c01","url":"http:\/\/www.letv.com\/ptv\/pplay\/77505\/1.html",

            "pic":"http:\/\/img1.c2.letv.com\/mms\/thumb\/2012\/05\/27\/4a9e475184bc2babf492961bbf2ba8bc\/4a9e475184bc2babf492961bbf2ba8bc_2.jpg"
        },

        {
            "key":2,"title":"\u7ec5\u58eb\u7684\u54c1\u683c02","url":"http:\/\/www.letv.com\/ptv\/pplay\/77505\/2.html",

            "pic":"http:\/\/img1.c2.letv.com\/mms\/thumb\/2012\/05\/28\/25faf71025166f8ebe1e4d6acbfe72e8\/25faf71025166f8ebe1e4d6acbfe72e8_2.jpg"
        },


</script >

------解决方案--------------------
探讨

引用:

key":(\d+)[^\n]+url":"([^"]+)"

试试这个

String p="key":(\d+)[^\n]+url":"([^"]+)"" 这样不能写。。。我对正则一点都不懂,我要写的是这样的:

Java code
Elements li=doct.select("script[type]").select("var LISTC……

------解决方案--------------------
java
Java code

    public static void main(String[] args) {
        String str = "\"key\":1,\"title\":\"\\u7ec5\\u58eb\\u7684\\u54c1\\u683c01\",\"url\":\"http://www.letv.com/ptv/pplay/77505/1.html\",";
        Matcher m = Pattern.compile("\"key\":(.+?),.+?\"url\":\"(.+?)\",.*?").matcher(str);
        while(m.find()){
            System.out.println(m.group(1));
            System.out.println(m.group(2));
        }
    }