tags:

views:

42

answers:

2

Hi

I am trying to convert between html-style markup such as bold and italics into my own custom markup format:

<b>Bold word</b> ---> * Bold word *

So the bold tag is converted to wrapping stars, etc.

Whats the easiest/best/fastest way to do this? Parsing the string manually is easy enough, but what about regular expressions?

I am using C# .NET 3.5 :)

A: 

This should do it:

s = Regex.Replace(s, "<b>(.*?)</b>", "*$1*");

as long as you don't have anything weird as bold tags inside other bold tags.

Guffa
+1  A: 

If your HTML is complex at all - nested tags, mismatched tags, etc. - I'd recommend using HTML Agility Pack to parse it. If you want to use RegEx for this, make sure to follow Jeff's blog - they use RegEx for StackOverflow's HTML parsing.

Jon Galloway