Regular expression to convert ul to textindent and back, with a different attribute value for first

Posted by chapmanio on Stack Overflow See other posts from Stack Overflow or by chapmanio
Published on 2010-04-01T17:02:31Z Indexed on 2010/04/01 18:03 UTC
Read the original article Hit count: 212

Filed under:
|

Hi,

This is a related to a previous question I have asked here, see the link below for a brief description as to why I am trying to do this.

Regular expression from font to span (size and colour) and back (VB.NET)

Basically I need a regex replace function (or if this can be done in pure VB then that's fine) to convert all ul tags in a string to textindent tags, with a different attribute value for the first textindent tag.

For example:

<ul>
   <li>This is some text</li>
   <li>This is some more text</li>
   <li>
      <ul>
         <li>This is some indented text</li>
         <li>This is some more text</li>
      </ul>
   </li>
   <li>More text!</li>
   <li>
      <ul>
         <li>This is some indented text</li>
         <li>This is some more text</li>
      </ul>
   </li>
   <li>More text!</li>
</ul>

Will become:

<textformat indent="0">
   <li>This is some text</li>
   <li>This is some more text</li>
   <li>
      <textformat indent="20">
         <li>This is some indented text</li>
         <li>This is some more text</li>
      </textformat>
   </li>
   <li>More text!</li>
   <li>
      <textformat indent="20">
         <li>This is some indented text</li>
         <li>This is some more text</li>
      </textformat>
   </li>
   <li>More text!</li>
</textformat>

Basically I want the first ul tag to have no indenting, but all nested ul tags to have an indent of 20.

I appreciate this is a strange request but hopefully that makes sense, please let me know if you have any questions.

Thanks in advance.

© Stack Overflow or respective owner

Related posts about regex

Related posts about vb.net