Question Highlight numbers using regex?

vlad__28

New member
Joined
Aug 22, 2012
Messages
4
Programming Experience
Beginner
Hello guys,
I have a question about regular expressions

I want to highlight in a richtextbox only telephone numbers...from a phrase or a sentence.
I managed till now to search the textbox and to show a message about all the numbers but i want to highlight them and i need your help please.

Thanks in advance
 
ok, so i tell the program to find in all the text, 10 numbers in rtb1.text

Dim r As Regex = New Regex("\b\d{10}", RegexOptions.Multiline)
Dim Mtch As MatchCollection = r.Matches(RichTextBox1.Text)

Now i am creating a result:

Dim result As String = ""
Dim i As Integer
For i = 0 To Mtch.Count - 1
Dim mat As Match = Mtch.Item(i)
result = result & vbCrLf & mat.Value

How can i link this result to rtb.select method ?

I am a beginer so excuse me for all the dumb questions.
Thanks alot for helping me
 
I mentioned the Match has Index property and Length property, that is the values you supply to Select method.
 
I understood that but tell me please if my code is correct till now or should i start from scratch. Your oppinion is valuable for me, thank you for replying.
 
It is correct, so far, but can be written much simpler:
For Each m As Match In Regex.Matches(RichTextBox1.Text, "\b\d{10}")

Next

RegexOptions.Multiline is not needed, it has a different meaning than you think.
 
Back
Top