Java regular expression gets the specified property value for the specified HTML tag and replaces the method _java

Source: Internet
Author: User
Tags stringbuffer

The

instance is as follows:

 public static string Repdomain (string source, string domain, string element, string attr
    ) {String img = "";
    Pattern P_image;
    Matcher M_image; String regex_img = "<" + element + "[^<>]*?\\s" + attr + "=[' \"]? (.*?) ['\"]? (\\s.*?)? 
    > ";
    P_image = Pattern.compile (regex_img, pattern.case_insensitive);
    M_image = P_image.matcher (source);
      while (M_image.find ()) {img = M_image.group (); Matcher m = pattern.compile ("href\\s*=\\s*\"? *?)
      (\ "|>|\\s+)"). Matcher (IMG);
        while (M.find ()) {String srcval = M.group (1);
        	if (Srcval.indexof ("/@tenant") >=0) {int idx = Srcval.indexof ("/@tenant");
        	StringBuffer temp = new StringBuffer ();
        	String dstval = temp.append (domain). Append (srcval.substring (idx+1)). ToString ();
        Source = Source.replace (Srcval, dstval);
  }} return source; }

The above is the Java regular expression for everyone to get the specified value of the specified attribute of the HTML tag and replace the method all the content, I hope that we support cloud-Habitat Community ~

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.