首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

哪位高手帮小弟我写一个正则表达式。多谢。

2012-09-23 
谁帮我写一个正则表达式。。谢谢。。。下面是script 里面的 内容我想得到HTML codekey:1,title:\u7ec5\u58

谁帮我写一个正则表达式。。谢谢。。。
下面是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));        }    } 

热点排行