Extract string between two words in Java -
i have following string. want extract string between 2 words <cases> , </cases>
using java. want extract string form valid xml per requirement.
<cases><final-results><row> <crdattim>2014-03-26-05.22.22.339840</crdattim> <recordcd>c</recordcd> <crnode>01</crnode> <ckey>2014-03-26-05.22.22.339840c01</ckey> <statcd>created</statcd> <unitcd>csmhcqa</unitcd> <wrktype>call</wrktype> <issues><row> <ikey>2014-03-26-05.22.22.193840t01</ikey> <prty>999</prty> <issueid>20140326-155047-dt81694</issueid> <subject>group</subject> <isstyp>group</isstyp> <isscat1>group inquiry</isscat1> </row></issues></row></final-results></cases><?xml version="1.0" encoding="utf-8"?> <response> <folderid>comm*h</folderid> </response>
i have tried following code. not working me.
pattern pattern = pattern.compile("<cases>(.*?)</cases>"); matcher matcher = pattern.matcher(string); while (matcher.find()) { system.out.println(matcher.group(1)); }
am doing mistake here?could please share idea solve issue? in advance.
try changing:
pattern pattern = pattern.compile("<cases>(.*?)</cases>");
into
pattern pattern = pattern.compile("<cases>(.*?)</cases>", pattern.dotall);
btw, if well-formed xml document, use parser instead of regex handle it.
Comments
Post a Comment