本文目录一览:
- 1、java 用正则表达式如何获取网页background:url(),或background-image:url()括弧里面的内容?
- 2、JAVA 正则表达式获取字符串中的URL和标题
- 3、java正则表达式截取URL
java 用正则表达式如何获取网页background:url(),或background-image:url()括弧里面的内容?
可以用如下正则:
/.*background[^;"]+url\(([^\)]+)\).*/gi
给你两个例子:
javascript:alert('background-image:url(aa.jpg)'.replace(/.*background[^;"]+url\(([^\)]+)\).*/gi,'$1'));
javascript:alert('background:#FFFFFF url(bb.jpg);color:#FF0000;'.replace(/.*background[^;"]+url\(([^\)]+)\).*/gi,'$1'));
JAVA 正则表达式获取字符串中的URL和标题
String s = "movie title=\"电影1\" src=\"\"/ movie title=\"电影2\" src=\"\"/";
String mode = "movie\\s*title=([^]*)src=(?=\"?http|https)([^]*)/";
Pattern p = Pattern.compile(mode);
Matcher m = p.matcher(s);
HashMapString, String map = new HashMapString, String();
while (m.find()) {
System.out.println("find...");
String title = m.group(1);
String url = m.group(2);
System.out.println("title:" + title + ",src:" + url);
map.put(title, url);
}
java正则表达式截取URL
String reg = ".*\\/\\/([^\\/\\:]*).*";
String str1 = " ";
System.out.println (str1.replaceAll (reg, "$1"));
String str2 = "";
System.out.println (str2.replaceAll (reg, "$1"));