regex - Regular Expression Split XML in Java -
i want split xml text parts:
xmlcontent = "<taga>text1<tagb>text2</tagb></taga>";
in c# use
string[] splitedtexts = regex.split(xmlcontent, "(<.*?>)|(.+?(?=<|$))");
the result
splitedtexts = ["<taga>", "text1", "<tagb>", "text2", "</tagb>", "</taga>"]
how can in java?
i have tried
string[] splitedtexts = xmlcontent.split("(<.*?>)");
but result not expecting.
the parameter split
defines delimiter split at. want split before <
, after >
hence can do:
string[] splitedtexts = xmlcontent.split("(?=<)|(?<=>)");
Comments
Post a Comment