[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Unable to do both size and colour within my bbcode

Posted on 2011-05-13
18
Medium Priority
?
472 Views
Last Modified: 2012-05-11
Im using [size=36pt][color=red]test[/color][/size]
but my html output is :   <span id="Label1">[size=36pt]<font color="red">test</font>[/size]</span>


My bbcode is
Imports Microsoft.VisualBasic

Public Class BBcode

    Shared Function BBcode(ByVal strTextToReplace As String) As String

        '//Define regex
        Dim regExp As Regex

        '//Regex for URL tag without anchor
        regExp = New Regex("\[url\]([^\]]+)\[\/url\]")
        strTextToReplace = regExp.Replace(strTextToReplace, "<a href=""$1"">$1</a>")

        '//Regex for URL with anchor
        regExp = New Regex("\[url=([^\]]+)\]([^\]]+)\[\/url\]")
        strTextToReplace = regExp.Replace(strTextToReplace, "<a href=""$1"">$2</a>")

        '//Image regex
        regExp = New Regex("\[img\]([^\]]+)\[\/img\]")
        strTextToReplace = regExp.Replace(strTextToReplace, "<img src=""$1"" />")

        '//Bold text
        regExp = New Regex("\[b\](.+?)\[\/b\]")
        strTextToReplace = regExp.Replace(strTextToReplace, "<b>$1</b>")

        '//Italic text
        regExp = New Regex("\[i\](.+?)\[\/i\]")
        strTextToReplace = regExp.Replace(strTextToReplace, "<i>$1</i>")

        '//Underline text
        regExp = New Regex("\[u\](.+?)\[\/u\]")
        strTextToReplace = regExp.Replace(strTextToReplace, "<u>$1</u>")

        '//Font size
        regExp = New Regex("\[size=([^\]]+)\]([^\]]+)\[\/size\]")
        strTextToReplace = regExp.Replace(strTextToReplace, "<font size="" $1"">$2</font>")

        '//Font color
        regExp = New Regex("\[color=([^\]]+)\]([^\]]+)\[\/color\]")
        strTextToReplace = regExp.Replace(strTextToReplace, "<font color=""$1"">$2</font>")

        '//Quote
        regExp = New Regex("\[quote=([^\]]+)\]([^\]]+)\[\/quote\]")
        strTextToReplace = regExp.Replace(strTextToReplace, "<div class=""quote"" align=""left""><div align=""left"" class=""quotetitle"">Originally Posted by <b>$1</b></div><i>"" $2 ""</i></div>")
        '//smiles


        Return strTextToReplace
    End Function
End Class

Open in new window


anyhelp would be great
0
Comment
Question by:runnerjp2005
  • 8
  • 5
  • 5
18 Comments
 
LVL 13

Expert Comment

by:Carl Bohman
ID: 35755985
You are specifically not working if there are other square brackets involved: ("\[size=([^\]]+)\]([^\]]+)\[\/size\]")
While italics and some of the others allow square brackets in the middle: ("\[i\](.+?)\[\/i\]")

You are probably safe in using the .+? approach instead of the [^\]]+ approach.  One thing that neither of these handles is nesting, where one code is contained in another: [ i]first layer[ i]second layer[ /i]first layer[ /i]

(The spaces are there because EE tries to interpret those codes and doesn't allow nesting.)

A more generic approach might be to look for a begin tag and its matching end tag (with no tags in between) and then replace them.  Repeat until all tags are replaced.  This replaces all tags from the inside out.  It's more complicated to code something like that, but it can be used to find all matching tags.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35756674
Try this modification which *should* handle nested tags and should perform a tad bit better since I've used the Compiled option:
Public Class BBcode

    Private Shared bbCodeRegex As Regex
    Private Shared urlRegex As Regex
    Private Shared urlAnchorRegex As Regex
    Private Shared imgRegex As Regex
    Private Shared boldRegex As Regex
    Private Shared italicRegex As Regex
    Private Shared underRegex As Regex
    Private Shared fSizeRegex As Regex
    Private Shared fColorRegex As Regex
    Private Shared quoteRegex As Regex

    Shared Sub New()
        bbCodeRegex = New Regex("\[([^\]]+)\]((?:[^\[]|\[(?!/\1\]))+)\[/\1\]", RegexOptions.Compiled)
        urlRegex = New Regex("\[url\]([^\]]+)\[\/url\]", RegexOptions.Compiled)
        urlAnchorRegex = New Regex("\[url=([^\]]+)\]([^\]]+)\[\/url\]", RegexOptions.Compiled)
        imgRegex = New Regex("\[img\]([^\]]+)\[\/img\]", RegexOptions.Compiled)
        boldRegex = New Regex("\[b\]((?:[^\[]|\[(?!/b\]))+)\[/b\]", RegexOptions.Compiled)
        italicRegex = New Regex("\[i\]((?:[^\[]|\[(?!/i\]))+)\[\/i\]", RegexOptions.Compiled)
        underRegex = New Regex("\[u\]((?:[^\[]|\[(?!/u\]))+)\[\/u\]", RegexOptions.Compiled)
        fSizeRegex = New Regex("\[size=([^\]]+)\]((?:[^\[]|\[(?!/size\]))+)\[\/size\]", RegexOptions.Compiled)
        fColorRegex = New Regex("\[color=([^\]]+)\]((?:[^\[]|\[(?!/color\]))+)\[\/color\]", RegexOptions.Compiled)
        quoteRegex = New Regex("\[quote=([^\]]+)\]((?:[^\[]|\[(?!/quote\]))+)\[\/quote\]", RegexOptions.Compiled)
    End Sub

    Shared Function BBcode(ByVal strTextToReplace As String) As String

        While bbCodeRegex.IsMatch(strTextToReplace)
            '//Regex for URL tag without anchor
            strTextToReplace = urlRegex.Replace(strTextToReplace, "<a href=""$1"">$1</a>")

            '//Regex for URL with anchor
            strTextToReplace = urlAnchorRegex.Replace(strTextToReplace, "<a href=""$1"">$2</a>")

            '//Image regex
            strTextToReplace = imgRegex.Replace(strTextToReplace, "<img src=""$1"" />")

            '//Bold text
            strTextToReplace = boldRegex.Replace(strTextToReplace, "<b>$1</b>")

            '//Italic text
            strTextToReplace = italicRegex.Replace(strTextToReplace, "<i>$1</i>")

            '//Underline text
            strTextToReplace = underRegex.Replace(strTextToReplace, "<u>$1</u>")

            '//Font size
            strTextToReplace = fSizeRegex.Replace(strTextToReplace, "<font size="" $1"">$2</font>")

            '//Font color
            strTextToReplace = fColorRegex.Replace(strTextToReplace, "<font color=""$1"">$2</font>")

            '//Quote
            strTextToReplace = quoteRegex.Replace(strTextToReplace, "<div class=""quote"" align=""left""><div align=""left"" class=""quotetitle"">Originally Posted by <b>$1</b></div><i>"" $2 ""</i></div>")

            '//smiles
        End While

        Return strTextToReplace
    End Function
End Class

Open in new window

0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35756695
One caveat of the above:  If you have a BB code that you have included in your list of acceptable codes, then the loop will continue forever. You'll need to add some logic to check for non-legal BB codes.

For example, the following would cause an endless loop:
[size=36pt][helloworld]test[/helloworld][/size]

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35756771
Actually, I withdraw my previous statement. It will not handle nested tags...   at least not properly. I'll give it some thought.
0
 
LVL 13

Expert Comment

by:Carl Bohman
ID: 35757211
This version handles nested tags and unknown tags.  What it does not handle is unmatched tags.
Imports System.Text.RegularExpressions

Public Class BBcode

    Private Shared bbCodeRegex As Regex
    Private Shared bbUnknownRegex As Regex
    Private Shared urlRegex As Regex
    Private Shared urlAnchorRegex As Regex
    Private Shared imgRegex As Regex
    Private Shared boldRegex As Regex
    Private Shared italicRegex As Regex
    Private Shared underRegex As Regex
    Private Shared fSizeRegex As Regex
    Private Shared fColorRegex As Regex
    Private Shared quoteRegex As Regex

    Shared Sub New()
        bbCodeRegex = New Regex("\[(\w+)[^\]]*\]((?:[^\[]|\[(?!/\1\]))+)\[/\1\]", RegexOptions.Compiled)
        bbUnknownRegex = New Regex("\[(\w+)[^\]]*\]((?:[^\[]|\[(?!/\1\]))+)\[/\1\]", RegexOptions.Compiled)
        urlRegex = New Regex("\[url\]([^\]]+)\[\/url\]", RegexOptions.Compiled)
        urlAnchorRegex = New Regex("\[url=([^\]]+)\]([^\]]+)\[\/url\]", RegexOptions.Compiled)
        imgRegex = New Regex("\[img\]([^\]]+)\[\/img\]", RegexOptions.Compiled)
        boldRegex = New Regex("\[b\]((?:[^\[]|\[(?!/b\]))+)\[/b\]", RegexOptions.Compiled)
        italicRegex = New Regex("\[i\]((?:[^\[]|\[(?!/i\]))+)\[\/i\]", RegexOptions.Compiled)
        underRegex = New Regex("\[u\]((?:[^\[]|\[(?!/u\]))+)\[\/u\]", RegexOptions.Compiled)
        fSizeRegex = New Regex("\[size=([^\]]+)\]((?:[^\[]|\[(?!/size\]))+)\[\/size\]", RegexOptions.Compiled)
        fColorRegex = New Regex("\[color=([^\]]+)\]((?:[^\[]|\[(?!/color\]))+)\[\/color\]", RegexOptions.Compiled)
        quoteRegex = New Regex("\[quote=([^\]]+)\]((?:[^\[]|\[(?!/quote\]))+)\[\/quote\]", RegexOptions.Compiled)
    End Sub

    Shared Function BBcode(ByVal strTextToReplace As String) As String
        Dim mMatch As Match = bbCodeRegex.Match(strTextToReplace)

        While mMatch.Success
            Select Case mMatch.Groups(1).ToString
                Case "url"
                    '//Regex for URL tag without anchor
                    strTextToReplace = urlRegex.Replace(strTextToReplace, "<a href=""$1"">$1</a>")

                    '//Regex for URL with anchor
                    strTextToReplace = urlAnchorRegex.Replace(strTextToReplace, "<a href=""$1"">$2</a>")

                Case "img"
                    '//Image regex
                    strTextToReplace = imgRegex.Replace(strTextToReplace, "<img src=""$1"" />")

                Case "b"
                    '//Bold text
                    strTextToReplace = boldRegex.Replace(strTextToReplace, "<b>$1</b>")

                Case "i"
                    '//Italic text
                    strTextToReplace = italicRegex.Replace(strTextToReplace, "<i>$1</i>")

                Case "u"
                    '//Underline text
                    strTextToReplace = underRegex.Replace(strTextToReplace, "<u>$1</u>")

                Case "size"
                    '//Font size
                    strTextToReplace = fSizeRegex.Replace(strTextToReplace, "<font size="" $1"">$2</font>")

                Case "color"
                    '//Font color
                    strTextToReplace = fColorRegex.Replace(strTextToReplace, "<font color=""$1"">$2</font>")

                Case "quote"
                    '//Quote
                    strTextToReplace = quoteRegex.Replace(strTextToReplace, "<div class=""quote"" align=""left""><div align=""left"" class=""quotetitle"">Originally Posted by <b>$1</b></div><i>"" $2 ""</i></div>")

                Case Else
                    strTextToReplace = bbUnknownRegex.Replace(strTextToReplace, "$2")
            End Select

            mMatch = bbCodeRegex.Match(strTextToReplace)

        End While

        BBcode = strTextToReplace
    End Function
End Class

Open in new window

0
 
LVL 13

Expert Comment

by:Carl Bohman
ID: 35757240
Actually, my code simply leaves unmatched tags alone without removing them.  If that's okay, then there's nothing else to do.  If you want to remove the unmatched tags, just do a final replace at the end that removes them.
0
 

Author Comment

by:runnerjp2005
ID: 35759976
bounsy: thats amazing...

Could i also ask if i where to add image to it how would i go about it??
<div align="center"><a href="~/emoticons/smiley.gif" title="smile"
onclick="wrapText(document.getElementById('inputforum'),':',')'); return false"><img 
src="~/emoticons/smiley.gif" border="0" alt=""/></a>
      <a href="~/emoticons/smiley.gif" title="smile"
onclick="wrapText(document.getElementById('inputforum'),':','('); return false"><img 
src="~/emoticons/sad.gif" border="0" alt=""/></a>
      <a href="~/emoticons/smiley.gif" title="smile"
onclick="wrapText(document.getElementById('inputforum'),';',')'); return false"><img 
src="~/emoticons/wink.gif" border="0" alt=""/></a>
      <a href="~/emoticons/smiley.gif" title="smile"
onclick="wrapText(document.getElementById('inputforum'),':','D'); return false"><img 
src="~/emoticons/cheesy.gif" border="0" alt=""/></a>
      <a href="~/emoticons/smiley.gif" title="smile"
onclick="wrapText(document.getElementById('inputforum'),';','D'); return false"><img 
src="~/emoticons/grin.gif" border="0" alt=""/></a>
      <a href="~/emoticons/smiley.gif" title="smile"
onclick="wrapText(document.getElementById('inputforum'),'::',')'); return false"><img 
src="~/emoticons/rolleyes.gif" border="0" alt=""/></a>
      <a href="~/emoticons/smiley.gif" title="smile"
onclick="wrapText(document.getElementById('inputforum'),'>:','('); return false"><img 
src="~/emoticons/angry.gif" border="0" alt=""/></a>
      <a href="~/emoticons/smiley.gif" title="smile"
onclick="wrapText(document.getElementById('inputforum'),':','o'); return false"><img 
src="~/emoticons/shocked.gif" border="0" alt=""/></a>
      <a href="~/emoticons/smiley.gif" title="smile"
onclick="wrapText(document.getElementById('inputforum'),'8',')'); return false"><img 
src="~/emoticons/cool.gif" border="0" alt=""/></a>
      <a href="~/emoticons/smiley.gif" title="smile"
onclick="wrapText(document.getElementById('inputforum'),'??','?'); return false"><img 
src="~/emoticons/huh.gif" border="0" alt=""/></a>
      <a href="~/emoticons/smiley.gif" title="smile"
onclick="wrapText(document.getElementById('inputforum'),':','p'); return false"><img 
src="~/emoticons/tongue.gif" border="0" alt=""/></a>
      <a href="~/emoticons/smiley.gif" title="smile"
onclick="wrapText(document.getElementById('inputforum'),':-','['); return false"><img 
src="~/emoticons/embarrassed.gif" border="0" alt=""/></a>
      <a href="~/emoticons/smiley.gif" title="smile"
onclick="wrapText(document.getElementById('inputforum'),':-','*'); return false"><img 
src="~/emoticons/undecided.gif" border="0" alt=""/></a>
      <a href="~/emoticons/smiley.gif" title="smile"
onclick="wrapText(document.getElementById('inputforum'),':-','\\'); return false"><img 
src="~/emoticons/lipssealed.gif" border="0" alt=""/></a>
      <a href="~/emoticons/smiley.gif" title="smile"
onclick="wrapText(document.getElementById('inputforum'),':-','*'); return false"><img 
src="~/emoticons/kiss.gif" border="0" alt=""/></a>
    <a href="~/emoticons/smiley.gif" title="smile"
onclick="wrapText(document.getElementById('inputforum'),':','*('); return false"><img 
src="~/emoticons/cry.gif" border="0" alt=""/></a></div>

Open in new window

0
 
LVL 13

Expert Comment

by:Carl Bohman
ID: 35760073
img is already in there.  A quick glance around the web shows that there are a lot of different ways smileys are done in BBCode or other formats.  What is the format you want to convert/support?  Do you have any examples?
0
 

Author Comment

by:runnerjp2005
ID: 35760114
well i just want to convert :) into the imagelink so is uses the same princaple as the img file but has to show the :) = smiley.gif as shown above snippit
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35760130
bounsy: thats amazing...
I agree. How on earth did you come up with all those fancy patterns...
0
 

Author Comment

by:runnerjp2005
ID: 35760378
kaufmed good point!

any idea how can do the smilie side

so
 :) would become <img src="happy.gif" alt="happy"/>
:( =  <img src="sad.gif" alt="sad"/>
;( =  <img src=cry.gif" alt="cry"/>

ect...
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35760661
Those are easy. I would just do a regular string.Replace() on those.
0
 
LVL 13

Expert Comment

by:Carl Bohman
ID: 35762604
I agree with kaufmed.  A series of string.Replace() would likely be the most straightforward.  Just make sure you start with the most complex and end with the least (in cases where it makes a difference, such as :-) vs *<:-) for example)
0
 

Author Comment

by:runnerjp2005
ID: 35768331
Would it be like this ??

Imports System.Text.RegularExpressions

Public Class BBcode

    Private Shared bbCodeRegex As Regex
    Private Shared bbUnknownRegex As Regex
    Private Shared urlRegex As Regex
    Private Shared urlAnchorRegex As Regex
    Private Shared imgRegex As Regex
    Private Shared boldRegex As Regex
    Private Shared italicRegex As Regex
    Private Shared underRegex As Regex
    Private Shared fSizeRegex As Regex
    Private Shared fColorRegex As Regex
    Private Shared quoteRegex As Regex
    Private Shared face As Regex

    Shared Sub New()
        bbCodeRegex = New Regex("\[(\w+)[^\]]*\]((?:[^\[]|\[(?!/\1\]))+)\[/\1\]", RegexOptions.Compiled)
        bbUnknownRegex = New Regex("\[(\w+)[^\]]*\]((?:[^\[]|\[(?!/\1\]))+)\[/\1\]", RegexOptions.Compiled)
        urlRegex = New Regex("\[url\]([^\]]+)\[\/url\]", RegexOptions.Compiled)
        urlAnchorRegex = New Regex("\[url=([^\]]+)\]([^\]]+)\[\/url\]", RegexOptions.Compiled)
        imgRegex = New Regex("\[img\]([^\]]+)\[\/img\]", RegexOptions.Compiled)
        boldRegex = New Regex("\[b\]((?:[^\[]|\[(?!/b\]))+)\[/b\]", RegexOptions.Compiled)
        italicRegex = New Regex("\[i\]((?:[^\[]|\[(?!/i\]))+)\[\/i\]", RegexOptions.Compiled)
        underRegex = New Regex("\[u\]((?:[^\[]|\[(?!/u\]))+)\[\/u\]", RegexOptions.Compiled)
        fSizeRegex = New Regex("\[size=([^\]]+)\]((?:[^\[]|\[(?!/size\]))+)\[\/size\]", RegexOptions.Compiled)
        fColorRegex = New Regex("\[color=([^\]]+)\]((?:[^\[]|\[(?!/color\]))+)\[\/color\]", RegexOptions.Compiled)
        quoteRegex = New Regex("\[quote=([^\]]+)\]((?:[^\[]|\[(?!/quote\]))+)\[\/quote\]", RegexOptions.Compiled)
        face = New Regex(":)", RegexOptions.Compiled)
    End Sub

    Shared Function BBcode(ByVal strTextToReplace As String) As String
        Dim mMatch As Match = bbCodeRegex.Match(strTextToReplace)

        While mMatch.Success
            Select Case mMatch.Groups(1).ToString
                Case "url"
                    '//Regex for URL tag without anchor
                    strTextToReplace = urlRegex.Replace(strTextToReplace, "<a href=""$1"">$1</a>")

                    '//Regex for URL with anchor
                    strTextToReplace = urlAnchorRegex.Replace(strTextToReplace, "<a href=""$1"">$2</a>")

                Case "img"
                    '//Image regex
                    strTextToReplace = imgRegex.Replace(strTextToReplace, "<img src=""$1"" />")

                Case "b"
                    '//Bold text
                    strTextToReplace = boldRegex.Replace(strTextToReplace, "<b>$1</b>")

                Case "i"
                    '//Italic text
                    strTextToReplace = italicRegex.Replace(strTextToReplace, "<i>$1</i>")

                Case "u"
                    '//Underline text
                    strTextToReplace = underRegex.Replace(strTextToReplace, "<u>$1</u>")

                Case "size"
                    '//Font size
                    strTextToReplace = fSizeRegex.Replace(strTextToReplace, "<font size="" $1"">$2</font>")

                Case "color"
                    '//Font color
                    strTextToReplace = fColorRegex.Replace(strTextToReplace, "<font color=""$1"">$2</font>")

                Case "quote"
                    '//Quote
                    strTextToReplace = quoteRegex.Replace(strTextToReplace, "<div class=""quote"" align=""left""><div align=""left"" class=""quotetitle"">Originally Posted by <b>$1</b></div><i>"" $2 ""</i></div>")
                Case ":)"
                    strTextToReplace = face.Replace(strTextToReplace, "smile")
                Case Else
                    strTextToReplace = bbUnknownRegex.Replace(strTextToReplace, "$2")
            End Select

            mMatch = bbCodeRegex.Match(strTextToReplace)

        End While

        BBcode = strTextToReplace
    End Function
End Class

Open in new window

0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 total points
ID: 35769403
Don't use a new regex object...  just do a string replace:
Imports System.Text.RegularExpressions

Public Class BBcode

    Private Shared bbCodeRegex As Regex
    Private Shared bbUnknownRegex As Regex
    Private Shared urlRegex As Regex
    Private Shared urlAnchorRegex As Regex
    Private Shared imgRegex As Regex
    Private Shared boldRegex As Regex
    Private Shared italicRegex As Regex
    Private Shared underRegex As Regex
    Private Shared fSizeRegex As Regex
    Private Shared fColorRegex As Regex
    Private Shared quoteRegex As Regex

    Shared Sub New()
        bbCodeRegex = New Regex("\[(\w+)[^\]]*\]((?:[^\[]|\[(?!/\1\]))+)\[/\1\]", RegexOptions.Compiled)
        bbUnknownRegex = New Regex("\[(\w+)[^\]]*\]((?:[^\[]|\[(?!/\1\]))+)\[/\1\]", RegexOptions.Compiled)
        urlRegex = New Regex("\[url\]([^\]]+)\[\/url\]", RegexOptions.Compiled)
        urlAnchorRegex = New Regex("\[url=([^\]]+)\]([^\]]+)\[\/url\]", RegexOptions.Compiled)
        imgRegex = New Regex("\[img\]([^\]]+)\[\/img\]", RegexOptions.Compiled)
        boldRegex = New Regex("\[b\]((?:[^\[]|\[(?!/b\]))+)\[/b\]", RegexOptions.Compiled)
        italicRegex = New Regex("\[i\]((?:[^\[]|\[(?!/i\]))+)\[\/i\]", RegexOptions.Compiled)
        underRegex = New Regex("\[u\]((?:[^\[]|\[(?!/u\]))+)\[\/u\]", RegexOptions.Compiled)
        fSizeRegex = New Regex("\[size=([^\]]+)\]((?:[^\[]|\[(?!/size\]))+)\[\/size\]", RegexOptions.Compiled)
        fColorRegex = New Regex("\[color=([^\]]+)\]((?:[^\[]|\[(?!/color\]))+)\[\/color\]", RegexOptions.Compiled)
        quoteRegex = New Regex("\[quote=([^\]]+)\]((?:[^\[]|\[(?!/quote\]))+)\[\/quote\]", RegexOptions.Compiled)
    End Sub

    Shared Function BBcode(ByVal strTextToReplace As String) As String
        Dim mMatch As Match = bbCodeRegex.Match(strTextToReplace)

        While mMatch.Success
            Select Case mMatch.Groups(1).ToString
                Case "url"
                    '//Regex for URL tag without anchor
                    strTextToReplace = urlRegex.Replace(strTextToReplace, "<a href=""$1"">$1</a>")

                    '//Regex for URL with anchor
                    strTextToReplace = urlAnchorRegex.Replace(strTextToReplace, "<a href=""$1"">$2</a>")

                Case "img"
                    '//Image regex
                    strTextToReplace = imgRegex.Replace(strTextToReplace, "<img src=""$1"" />")

                Case "b"
                    '//Bold text
                    strTextToReplace = boldRegex.Replace(strTextToReplace, "<b>$1</b>")

                Case "i"
                    '//Italic text
                    strTextToReplace = italicRegex.Replace(strTextToReplace, "<i>$1</i>")

                Case "u"
                    '//Underline text
                    strTextToReplace = underRegex.Replace(strTextToReplace, "<u>$1</u>")

                Case "size"
                    '//Font size
                    strTextToReplace = fSizeRegex.Replace(strTextToReplace, "<font size="" $1"">$2</font>")

                Case "color"
                    '//Font color
                    strTextToReplace = fColorRegex.Replace(strTextToReplace, "<font color=""$1"">$2</font>")

                Case "quote"
                    '//Quote
                    strTextToReplace = quoteRegex.Replace(strTextToReplace, "<div class=""quote"" align=""left""><div align=""left"" class=""quotetitle"">Originally Posted by <b>$1</b></div><i>"" $2 ""</i></div>")
                Case Else
                    strTextToReplace = bbUnknownRegex.Replace(strTextToReplace, "$2")
            End Select

            mMatch = bbCodeRegex.Match(strTextToReplace)

        End While

        strTextToReplace = strTextToReplace.Replace(":)", "<img src=""happy.gif"" alt=""happy""/>")
        strTextToReplace = strTextToReplace.Replace(":(", "<img src=""sad.gif"" alt=""sad""/>")
        strTextToReplace = strTextToReplace.Replace(";(", "<img src=""cry.gif"" alt=""cry""/>")
        
        BBcode = strTextToReplace
    End Function
End Class

Open in new window

0
 

Author Comment

by:runnerjp2005
ID: 35769477
hey kaufmed.. Where is the single replace in the code above??
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35769546
Lines 78, 79, and 80--one for each smiley.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35769773
Not to sound ungrateful, but bounsy did help with the switch statement  and the nested tags  : )
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
We are witnesses that everyone is saying that our children shouldn't "play" with a technology because it is dangerous. This article is going to prove that they are wrong.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question