Packagedemo;ImportJava.io.File;ImportJava.text.Collator;Importjava.util.ArrayList;Importjava.util.Arrays;ImportJava.util.Comparator;Importjava.util.List;ImportJava.util.regex.Matcher;ImportJava.util.regex.Pattern; Public classDemo {@SuppressWarnings ("Unchecked") Public Static voidMain (string[] args) {String content= "Fdsafewafdsfasdfffweaer" + "<i MG alt=\ "\" Src=\ "http://lady.people.com.cn/NMediaFile/2015/1012/MAIN201510120941000081018729633. Jpg\ "width=\" 500\ "height=\" 750\ "style=\" border:none;\ ">FAWEFDSF" + "43243543" + " FASDFAF "; Match (content); } Public Static voidMatch (String content) {Matcher m= Pattern.compile ("src=\" http://.*?\ ""). Matcher (content); while(M.find ()) {String match=M.group ();
pattern.case_insensitive ignore ' jpg ' case Matcher k=pattern.compile ("src=\" http://.*?) jpg, pattern.case_insensitive). Matcher (Match); if(K.find ()) {System.out.println (match); } } } }
PS: This code can be used to capture the HTML page of the image link matching, this section of the code matches the image is JPG format, if you want to match other formats similarly.
Java implementation regular matching picture links obtained in HTML