Matcher parse the value of the map structure into a string (level two structure)

Source: Internet
Author: User
/** * Class Function Description * @version * @author Flyer March 12, 2018 PM 5:41:08 * @since 1.8 * * public class Matchstrutil { /** * @param args */public static void main (string[] args) {String Srctext = "[{Voice=bo
        Ytype, picture=http://xxj.jpg},{voice=, picture=123.jpg}] "; String findText = "Picture";
        The ending string is "}" list<string> r1 = Appearkey (Srctext, FindText, "}");
        
        SYSTEM.OUT.PRINTLN (R1); String findText1 = "Voice";
        The ending string is "," list<string> R11 = Appearkey (Srctext, FindText1, ",");
    System.out.println (R11); /** * Gets the value corresponding to the specified string * * @param srctext Source String * @param findText the string to find * @param endstr with what character 
        String End * @return */public static list<string> Appearkey (String srctext, String findtext,string endstr) {
list<string> result =new arraylist<> ();
        int count = 0;
     Pattern p = pattern.compile (FindText);   Matcher m = P.matcher (Srctext); while (M.find ()) {//count++;//System.out.println (M.start ());//The beginning of string occurrences string shen
            Gyustr =srctext.substring (M.end () +1);
            int firststr = Shengyustr.indexof (ENDSTR);
String value = shengyustr.substring (0,FIRSTSTR);
            System.out.println (shengyustr.substring (0,FIRSTSTR));
            if (Value!=null &&value.length () >0) {Result.add (value);
    }//System.out.println (M.end ());//The end position where the string appears} return result; }
    
}

Output

[Http://xxj.jpg, 123.jpg] [Boytype]

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.