Got more questions? Find advice on: ASP | SQL | XML | Windows
Welcome to RegexAdvice Sign in | Join | Help

Convert BBCode, [color] tags, to HTML

  •  04-07-2008, 8:55 AM

    Convert BBCode, [color] tags, to HTML

    Greetings.

     I have some problems using a Regex replace for converting the following BBCode:

    string bbCode = " [ color=red]Red[/color]";
    Regex regExp = new Regex(@"\[ color=([^\]]+)\]([^\]]+)\[\/color\]");
    string htmlCode = regExp.Replace(bbCode, "<span style=\'color: $1\'>$2</span>');

    Essentially, that works well, however, the actual BBCode contains an annoying ":123abc" after the color name:
    string bbCode = "[ color=red:123abc]Red[ /color:123abc]";

    It can be any type of alphanumeric characters after the colon.

    (Sorry, I had to put some spaces after the left brackets, in order to make it post correctly here.) 

    So, the question is: How do I strip out everything, and including the colon?

    Thanks,

    Regards,

    M

     

    Filed under: , , , ,
View Complete Thread