How to pretty-print XML with a regular expression?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andrew Montgomery

    How to pretty-print XML with a regular expression?

    Here's a challenge for all the hard-core regexp writers out there:
    pretty-printing XML in as few regular expressions as possible.
    Basically what I'm looking for is a method of converting this:

    <tag1 attr="value"><t ag2 earth="round">< tag3
    bob="youruncle" ></tag3><tag4 perl="cool" /></tag2></tag1>

    into this:

    <tag1 attr="value">
    <tag2 earth="round">
    <tag3 bob="youruncle" >
    </tag3>
    <tag4 perl="cool" />
    </tag2>
    </tag1>

    with as little code as possible. Thanks!
Working...