S
Steve Dunn
I'm stuck with a regular expression that closes tags if a closing tag
doesn't already exist. It's probably easier to demonstrate than explain, so
here goes:
I need to turn the following structure:
<TAG1>
<TAG2>foo
<FOOBAR>
<TAG3>I'm ok</TAG3>
</TAG1>
into the follow:
<TAG1>
<TAG2>foo</TAG2>
<FOOBAR />
<TAG3>I'm ok</TAG3>
</TAG1>
So, TAG1 and TAG3 are left alone, as they contains a closing tag, TAG2 is
closed because there's text and no closing tag, and <FOOBAR> is closed
because there's no text and closing tag.
Any help very much appreciated,
Thanks,
Steve.
p.s. I'm using the .NET regex classes
doesn't already exist. It's probably easier to demonstrate than explain, so
here goes:
I need to turn the following structure:
<TAG1>
<TAG2>foo
<FOOBAR>
<TAG3>I'm ok</TAG3>
</TAG1>
into the follow:
<TAG1>
<TAG2>foo</TAG2>
<FOOBAR />
<TAG3>I'm ok</TAG3>
</TAG1>
So, TAG1 and TAG3 are left alone, as they contains a closing tag, TAG2 is
closed because there's text and no closing tag, and <FOOBAR> is closed
because there's no text and closing tag.
Any help very much appreciated,
Thanks,
Steve.
p.s. I'm using the .NET regex classes