java正则表达式如何匹配字符串

来自:互联网
时间:2020-09-27
阅读:

java正则表达式匹配字符串的方法:

使用tostring

private static List<String> getImage(String str){
        List<String> tmp=new ArrayList<String>();
        String regex="<img src=\"([^\"]+?)\" />";
        Pattern pattern = Pattern.compile(regex);  
        Matcher matcher = pattern.matcher(str); 
        System.out.println(str);
        while(matcher.find()){
        
            tmp.add(matcher.group(1).toString());
            
        }
        return tmp;       
    }
返回顶部
顶部