I want to convert SGML to XML with regrex. Like:
convert:
<a><ab><abc>111<abc2>222</ab></a>
to:
<a><ab><abc>111</abc><abc2>222</abc2></ab></a>
And I write the following code to do the conversion:
String a = "<a><ab><abc>abc<abc2>abc2</ab></a>";
a = a.replaceAll("<([^<>]+?)>([^<>]+?)<(?!/\\$1>)", "<$1>$2</$1><");
System.out.println(a);
However the result is not the expected one:
<a><ab><abc>111</abc><abc2>222</ab></a>
My question, is it possible to do the conversion with regex? If yes, What's the issue in my code?