求个正则表达式
有个字符串是这样的格式var url='';url= '418134' + url;url= '62_5'+url;url= '36580' + url;url='8857136' + url;url= '80cefa'+url;url='3d7f02d'+ url;url= '8695ce52'+url;url= '1abc1e'+ url;url= '__K=28' + url;url= '/13441/?' +url;url= '3' + url;url= 'l/Book/1' +url;url= 'Htm' + url;url='/' + url;;window.location=url;
现在我想得到他跳转的地址,正则的规则这么写啊?
我用
Pattern pattern = Pattern.compile("\'(.+)\'");
Matcher matcher = pattern.matcher(el.html());
while (matcher.find()){
System.out.println(matcher.group());
}
得不到单引号里面里的值。。。 --------------------编程问答-------------------- --------------------编程问答--------------------
public class Test3{
public static void main(String[] args)
{
List<String> list=getContext();
String result="";
for(String s:list){
result+=s;
}
System.out.println(result);//结果:4181344425
}
//正则提取
public static List<String> getContext() {
//String html="kk<p>123456</p>ssss";
String html="hreh'418134'hregeg'4425'";
List<String> resultList = new ArrayList<String>();
Pattern p = Pattern.compile("\'(.*?)\'");//匹配<p>开头,</p>结尾的文档
Matcher m = p.matcher(html );//开始编译
while (m.find()) {
resultList.add(m.group(1));//获取被匹配的部分
System.out.println(m.group());//输出结果:'418134'和'4425'
}
return resultList;
}
}
虽然不是很明白,但是估计差不多就是result那个结果吧? --------------------编程问答-------------------- +1 --------------------编程问答-------------------- 解决了吗?你想得到里面的数字? --------------------编程问答-------------------- 正则的话'(.*?)'
另外,实施Rhino,直接js引擎eval出来,得到url的值??
补充:Java , Java EE