Java regular expression gets the URL address in the src of the <img src> in the HTML string

Source: Internet
Author: User

/*** Get the address of the picture on the webpage*/     Public StaticSet<string>getimgstr (String htmlstr) {Set<String> pics =NewHashset<>(); String img= "";        Pattern P_image;        Matcher M_image; //String regex_img = "]*?> "; //Image Link AddressString regex_img = "]*?> "; P_image=pattern.compile (regex_img, pattern.case_insensitive); M_image=P_image.matcher (HTMLSTR);  while(M_image.find ()) {//get  DataIMG =M_image.group (); //match src data in Matcher m = pattern.compile ("src\\s*=\\s*\"? *?) (\ "|>|\\s+)"). Matcher (IMG);  while(M.find ()) {Pics.add (M.group (1)); }        }        returnpics; }

Java regular expression gets the URL address in the src of the in the HTML string

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.