Home >Java >JavaBase >How to match string with java regular expression

How to match string with java regular expression

coldplay.xixi
coldplay.xixiOriginal
2020-09-27 14:55:3418274browse

How to match strings with java regular expressions: use tostring, the code is [while(matcher.find()){tmp.add(matcher.group(1).toString());}].

How to match string with java regular expression

Java regular expression matching string method:

Use 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;       
    }

Related learning recommendations: java basics

The above is the detailed content of How to match string with java regular expression. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn