Home > Java > JavaBase > body text

How to match string with java regular expression

coldplay.xixi
Release: 2020-09-27 14:55:34
Original
18204 people have browsed it

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;       
    }
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!