Java正则表达式应用

查找html中的图片

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class PicDownload {

    public static void main(String[] args) throws Exception{
        String content = "<html><img data-src=\"test1\">cc<img data-src=\"test2\"></html>";
        Pattern p = Pattern.compile("<img data-src=[\"\'](.*?)[\"\'].*?>");
        Matcher m = p.matcher(content);
        boolean b = m.find();
        while(b){
            String path = m.group(1);
            System.out.println(path);
            b = m.find();
        }
    }

}

输出结果

test1
test2

猜你喜欢

转载自www.cnblogs.com/TheoryDance/p/10235972.html
今日推荐