I'm trying to format a XML document, so I pass a string into a method, such as:
"<foo><subfoo><subsubfoo>content</subsubfoo></subfoo><subfoo/></foo>"
And I'm trying to split it based on finding the tags. I want to split each element (a tag, or content) into a unique string, such as:
"<foo>", "<subfoo>", "<subsubfoo>", "content", "</subsubfoo>", "</subfoo>", "<subfoo/>", "</foo>"
And to this end I use the code:
string findTagString = "(?<=<.*?>)";
Regex findTag = new Regex(findTagString);
List<string> textList = findTag.Split(text).ToList();
The above code works fine, except it doesn't split "content" into its own string, instead:
"<foo>", "<subfoo>", "<subsubfoo>", "content</subsubfoo>", "</subfoo>", "<subfoo/>", "</foo>"
Is there a way to rewrite the Regex to acomplish this, the splitting of non-matches into their own string?
Or, rephrased: Is it possible to split a string before AND after a Regex match?