Java regex matches nothing -


string string = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +             "<request>\n" +             "  <item>\n" +             "    <type>c0401</type>\n" +             "    <invdate>20150301</invdate>\n" +             "    <no>pk1000000</no>\n" +             "  </item>\n" +             "  <item>\n" +             "    <type>c0401</type>\n" +             "    <invdate>20150301</invdate>\n" +             "    <no>pk1000002</no>\n" +             "  </item>\n" +             "</request>";     pattern pattern = pattern.compile("(<item>)(.*)(</item>)");     matcher matcher = pattern.matcher(string);      list<string> listmatches = new arraylist<string>();      while(matcher.find())     {         listmatches.add(matcher.group(2));     } 

if replace item type or invdate or no, can content.

looking answer. thanks

you have use option pattern.dotall multiline maches:

pattern pattern = pattern.compile("(<item>)(.*?)(</item>)",pattern.dotall); 

quantifier: *? between 0 , unlimited times, few times possible, expanding needed [lazy]


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -