Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Reply
 
LinkBack Thread Tools Display Modes
Old 02-11-2011, 04:33 PM   #1 (permalink)
VIP
 
RazorbladeXtreme's Avatar
 
Join Date: May 2008
Location: Jaipur
Posts: 187
Default RegEx Syntax Highlighting in RTB [VB.net]


There are numerous examples of Syntax Highlighting using RegEx floating over the web but all are way too length and complicated codes for someone fairly new to Vb.net.

I found this code which uses Strings

Code:
Private Sub RichTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RichTextBox1.TextChanged

Dim words As New List(Of String)

words.Add("<html>")

words.Add("<body>")

If RichTextBox1.Text.Length > 0 Then

Dim selectStart As Integer = RichTextBox1.SelectionStart

RichTextBox1.Select(0, RichTextBox1.Text.Length)

RichTextBox1.SelectionColor = Color.Black

RichTextBox1.DeselectAll()

For Each oneWord As String In words

Dim pos As Integer = 0

Do While RichTextBox1.Text.ToUpper.IndexOf(oneWord.ToUpper, pos) >= 0

pos = RichTextBox1.Text.ToUpper.IndexOf(oneWord.ToUpper, pos)

RichTextBox1.Select(pos, oneWord.Length)

RichTextBox1.SelectionColor = Color.Blue

pos += 1

Loop

Next

RichTextBox1.SelectionStart = selectStart

End If

End Sub
I wanted to use Regular Expressions using something like

Code:
Dim words As New List(Of Regex)

words.Add(New Regex("<html.*?>", RegexOptions.IgnoreCase))
but nothing worked out as indexOf() or similar position finding functions would take Strings and not Expressions.
__________________
Twitter: twitter.com/SharmaTushar
Facebook: facebook.com/tushar.sharma
RazorbladeXtreme is offline   Reply With Quote
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


 
Latest Threads
- by Charan
- by Sarath
- by clmlbx

Advertisement




All times are GMT +5.5. The time now is 12:36 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2