Code:
Dim current_cursor_position As Integer = Me.rtbCode.SelectionStart
'This is useful to get a hold of where is the current cursor at
'this will be needed once all coloring is done, and we need to return
Dim html() As String = {"<!DOCTYPE html>", "<!DOCTYPE html>", "<html>", "</html>", "<head>", "</head>", "<style>", "</style>",
"<body>", "</body>", "pre>", "</pre>", "<!DOCTYPE>", "<title>", "<ul>", "</ul>", "<li>", "</li>",
"</title>", "<a>", "</a>", "<abbr>", "<address>", "<area>", "</area>", "<article>", "<b>", "</b>", "<p>", "</p>",
"<aside>", "<audio>", "<acronym>", "<applet>", "<b>", "<base>", "<div>", "</div>", "<span>", "</span>",
"<blockquote>", "<br>", "<button>", "</button>",
"<basefont>", "<bgsound>", "<big>", "<blink>", "<img>", "</img>",
"<input>", "</input>"}
Dim pattern As String = "<(.)*?>"
Dim matches As MatchCollection = Regex.Matches(Me.rtbCode.Text, pattern)
For Each match In matches
Me.rtbCode.Select(match.index, match.length)
Dim lookFor As String = match.ToString
If match.ToString.Contains(" ") Then 'Checking if tag contains properties
lookFor = match.ToString.Substring(0, match.ToString.IndexOf(" ")) & ">"
'This line will strip away any extra properties, values, and will
' close up the tag to be able to look for it in the allowed array
End If
If html.Contains(lookFor.ToString.ToLower) Then
'The tag is part of the allowed tags, and can be colored blue.
Me.rtbCode.SelectionColor = Color.Blue
Else
'This tag is not recognized, and shall be colored black..
Me.rtbCode.SelectionColor = Color.Black
End If
Next
Me.rtbCode.SelectionStart = current_cursor_position
'Returning cursor to its original position
Me.rtbCode.SelectionLength = 0
'De-Selecting text (if it was selected)
Me.rtbCode.SelectionColor = Color.Black
'new text will be colored black, until
'recognized as HTML tag.
I'm not understanding this part...