How to match strings with java regular expressions: use tostring, the code is [while(matcher.find()){tmp.add(matcher.group(1).toString());}].
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!