I want to split some XML text into parts:
xmlcontent = "<tagA>text1<tagB>text2</tagB></tagA>";
In C# i use
string[] splitedTexts = Regex.Split(xmlcontent, "(<.*?>)|(.+?(?=<|$))");
The result is
splitedTexts = ["<tagA>", "text1", "<tagB>", "text2", "</tagB>", "</tagA>"]
How can do it in Java?
I have tried
String[] splitedTexts = xmlcontent.split("(<.*?>)");
but the result is not like my expecting.
splitdefines the delimiter to split at. You seem to want to find matches.regexpackage to find matches or refine the pattern to find delimiters as in my answer.