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

How to match string with java regular expression

coldplay.xixi
Release: 2020-09-27 14:55:34
Original
18318 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
Latest Issues
Install JAVA
From 1970-01-01 08:00:00
0
0
0
Unable to install java
From 1970-01-01 08:00:00
0
0
0
Can java be used as the backend of the web?
From 1970-01-01 08:00:00
0
0
0
Is this in Java language?
From 1970-01-01 08:00:00
0
0
0
Help: JAVA encrypted data PHP decryption
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template