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

Posted by chapmanio on Stack Overflow See other posts from Stack Overflow or by chapmanio
Published on 2010-03-26T13:07:28Z Indexed on 2010/03/26 13:13 UTC
Read the original article Hit count: 195

Filed under:
|
|
|

Hi,

I am looking for a regular expression that can convert my font tags (only with size and colour attributes) into span tags with the relevant inline css. This will be done in VB.NET if that helps at all.

I also need a regular expression to go the other way as well.

To elaborate below is an example of the conversion I am looking for:

<font size="10">some text</font>

To then become:

<span style="font-size:10px;">some text</span>

So converting the tag and putting a "px" at the end of whatever the font size is (I don't need to change/convert the font size, just stick px at the end).

The regular expression needs to cope with a font tag that only has a size attribute, only a color attribute, or both:

<font size="10">some text</font>

<font color="#000000">some text</font>

<font size="10" color="#000000">some text</font>

<font color="#000000" size="10">some text</font>

I also need another regular expression to do the opposite conversion. So for example:

<span style="font-size:10px;">some text</span>

Will become:

<font size="10">some text</font>

As before converting the tag but this time removing the "px", I don't need to worry about changing the font size.

Again this will also need to cope with the size styling, font styling, and a combination of both:

<span style="font-size:10px;">some text</span>

<span style="color:#000000;">some text</span>

<span style="font-size:10px; color:#000000;">some text</span>

<span style="color:#000000; font-size:10px;">some text</span>

I apprecitate this is a lot to ask, I am hopeless with regular expressions and need to find a way of making these conversions in my code. Thanks so much to anyone that can/is willing to help me!

© Stack Overflow or respective owner

Related posts about regex

Related posts about vb.net