62,614
社区成员
发帖
与我相关
我的任务
分享
private static final String STYLE_IMG = "url\\s*\\([\"\']?(.+)?[\"\']?\\)";
private static final Pattern PATTERN_FOR_STYLE_IMG = Pattern.compile(STYLE_IMG,Pattern.CASE_INSENSITIVE);
public static void main(String[] args){
String str = "background:url('css/bg.png')\n " +
" background:url('css/bg.png')\n"+
" background:url('css/bg.png') ";
StringBuffer newStyleStr = new StringBuffer();
Matcher imgMatcher = PATTERN_FOR_STYLE_IMG.matcher(str);
while(imgMatcher.find()){
System.out.println("123"); //这样能打印3次, 也就是3个URL都解析到了
}
//imgMatcher.appendTail(newStyleStr);
private static final String STYLE_IMG = "url\\s*\\([\"\']?(.+)?[\"\']?\\)";
private static final Pattern PATTERN_FOR_STYLE_IMG = Pattern.compile(STYLE_IMG,Pattern.CASE_INSENSITIVE);
public static void main(String[] args){
String str = "background:url('css/bg.png') background:url('css/bg.png') background:url('css/bg.png')";
StringBuffer newStyleStr = new StringBuffer();
Matcher imgMatcher = PATTERN_FOR_STYLE_IMG.matcher(str);
while(imgMatcher.find()){
System.out.println("123"); //这样只打印一次 也就是3个URL只解析到一个
//imgMatcher.appendReplacement(newStyleStr,"url(1)");
}
//imgMatcher.appendTail(newStyleStr);
"url\\s*\\([\"\']?([^\"\']+)?[\"\']?\\)"
private static final String STYLE_IMG = "url\\s*\\([\"\']?.+?[\"\']?\\)";