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]