473,387 Members | 1,440 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Regex Output to Textbox

Hi -

I am extremely new to programming so I apologize in advance for my lack
of knowlege, vocabulary and if my code is sloppy. I will take any
suggestions to clean up my code and to follow any best pratices that I
missed. I am taking a stab at writing a program through Visual Basic
2005 Express Edition that will (don't laugh...) keep track, search
through and find new friends with specific interests on myspace. The
functionality of myspace is quite a let down so I thought I would try
to create a program to fill my need. I am stuck at the moment on
trying to do a httpWebRequest and regex to give me an output into a
textbox of friend IDs. Here my code so far that I have figured out
through researching the boards, msdn and using Expresso for my regular
expression:

' Imports System.Text.RegularExpressions

Private Sub GetIDsButton_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles GetIDsButton.Click

Dim myURL As String = ToolStripTextBox1.Text
Dim myReg As Net.HttpWebRequest =
DirectCast(Net.WebRequest.Create(myURL), _
Net.HttpWebRequest)
Dim myResp As Net.HttpWebResponse = _
DirectCast(myReg.GetResponse(), Net.HttpWebResponse)
Dim myStream As IO.Stream = myResp.GetResponseStream()
Dim myreader As New IO.StreamReader(myStream)
Dim myPage As String = myreader.ReadToEnd()
myResp.Close()

'' Regular expression built for Visual Basic on: Thu, Jul 6,
2006, 12:07:39 PM
'' Using Expresso Version: 2.1.2150, http://www.ultrapico.com
''
'' A description of the regular expression:
'' '' [1]: A numbered capture group. [\d{5,9}]
'' Any digit, between 5 and 9 repetitions
'' Match a suffix but exclude it from the capture. ["><img\b]
'' "><img\b
'' "><img
'' First or last character in a word
'
Dim r As Regex = New Regex( _
"(\d{5,9})(?=""><img\b)" + vbCrLf + "", _
RegexOptions.IgnoreCase _
Or RegexOptions.IgnorePatternWhitespace _
)
Dim m As RegularExpressions.Match
Dim mLink As RegularExpressions.Match
For Each m In r.Matches(myPage)
Next
TextBox1.Text = mLink

I am getting the error: 'Error 1 Value of type
'System.Text.RegularExpressions.Match' cannot be converted to
'String'.

Can someone help me figure out what I am doing wrong?

Jul 7 '06 #1
4 1761
I haven't checked yet, but isn't Matches the collection of matches
returned?
Therefore your code would need to look like this:

For Each m In r.Matches
Next

Then of course you still need to pass your page, probably another
method I thinks.
But I could be wrong. The error indicates a type mismatch and I am
guessing that r.Matches(myPage) returns strings.
For Each m In r.Matches(myPage)
Next
Jul 7 '06 #2
Thanks for writing me back Steven. I think you are exactly right. It
seems that I am trying to return a string from the collection of
matches which isn't possible. However I am totally lost about how to
work around this. I think I figure out how to get my webpage into a
stream and I think I even have the regular expression figured out, but
I am not sure how to pass in my streamed text to the regular expression
and then have the results output into a textbox. Any ideas? Also,
just to clarify the error is highlighting mLink and saying "Value of
type 'System.Text.RegularExpressions.Match' cannot be converted to
'String'." Which I think it is telling me exactly what you wrote
below, but I just wanted to add that.

Any ideas how I should code this to run my stream through and output
into a textbox?

Thanks again for your help.
Steven Nagy wrote:
I haven't checked yet, but isn't Matches the collection of matches
returned?
Therefore your code would need to look like this:

For Each m In r.Matches
Next

Then of course you still need to pass your page, probably another
method I thinks.
But I could be wrong. The error indicates a type mismatch and I am
guessing that r.Matches(myPage) returns strings.
For Each m In r.Matches(myPage)
Next
Jul 7 '06 #3

Sarah wrote:
Hi -

I am extremely new to programming so I apologize in advance for my lack
of knowlege, vocabulary and if my code is sloppy. I will take any
suggestions to clean up my code and to follow any best pratices that I
missed. I am taking a stab at writing a program through Visual Basic
2005 Express Edition that will (don't laugh...) keep track, search
through and find new friends with specific interests on myspace. The
functionality of myspace is quite a let down so I thought I would try
to create a program to fill my need. I am stuck at the moment on
trying to do a httpWebRequest and regex
I would strongly suggest you stop trying to use regex to parse html,
and instead track down HtmlAgilityPack which parses html and gives you
a nice document tree back. As a newbie this might look intimidating to
start with but believe me, getting used to working a document tree will
in the short and long term be far more enjoyable and useful than trying
to get regexes for parsing html right.

--
Larry Lard
Replies to group please
When starting a new topic, please mention which version of VB/C# you
are using

Jul 7 '06 #4
Check Larry's post below.
I'm not 100% on the syntax you need and MSDN site is running too slow
to use currently (is it just me?) so I can't check usage of the REGEX
class.

Larry's suggestion with a tree representation of elements sounds quite
useful, but not sure what sort of speed performance issues there are.

Jul 11 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Alan Pretre | last post by:
Can anyone help me figure out a regex pattern for the following input example: xxx:a=b,c=d,yyy:e=f,zzz:www:g=h,i=j,l=m I would want four matches from this: 1. xxx a=b,c=d 2. yyy e=f 3....
2
by: rjb | last post by:
Hi there I have a text file which looks like the one below. I'm trying to write a program which will go through each of those lines (for each section separated by an empty line) and give me: ...
8
by: rjb | last post by:
Hi! Could somebody have a look and help me to optimize the code below. It may look like very bad way of coding, but this stuff is very, very new for me. I've included just few lines. Regex...
2
by: Hailstorm | last post by:
How can I control if "a textbox is empty or not" with regex validation? I don't want to use required field validator because I have a masked textbox control and it has "ValidationExpress" property....
3
by: Peter Proost | last post by:
Hi group, can the following be done by using a regex, I want a textbox only to contain numbers or . / + - ^ , but I've never used a regex before so I don't know how to go about it. Could I for...
8
by: Just Me | last post by:
I want to use regular expressions to search a string, give the user the option of replacing, and then maybe replacing the data - using reg expressions for the search and the replace strings. ...
11
by: Steve | last post by:
Hi All, I'm having a tough time converting the following regex.compile patterns into the new re.compile format. There is also a differences in the regsub.sub() vs. re.sub() Could anyone lend...
2
by: Mick Walker | last post by:
Hi All, I would like to know how I can limit users to only registering usernames which have alphanumberic characters and one underscore. From what I understand is I can use a regex to do this....
4
by: Flomo Togba Kwele | last post by:
I am having difficulty writing a Regex constructor. A line has a quote(") at its beginning and its end. I need to strip both characters off. If the line looks like "1", I need the result to be 1....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.