vb.net - Regex Matches

hello there,
I a web page I have a lot of codes like this with different numbers

<SPAN class=fcg>2 downloaded images</SPAN>

I would like to make a Regex Matches to match the span that have numbers over 30..
how can I do that?
LVL 1
XK8ERAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nepaluzCommented:
Try this

Dim WebPageResult As string

Dim RegexResult = Regex.Match(rResult, "<SPAN class=fcg>\s*([\s\S]*?)\s*</SPAN>", RegexOptions.Multiline).Groups(0).ToString


From there you can parse the result to retrieve the string value.

(ps. Could you mark the question you posted here: http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_26705597.html?cid=1576
nepaluzCommented:
NOTE: The rResult is actually the WebPageResult I declared above!
XK8ERAuthor Commented:
for some reason I am getting this error


>>String cannot be of zero length.

tag = m.Value.Replace(m.Groups("text").Value, txt)




Dim txt2highlight As String = "downloaded images"
        Dim pattern As String = "<SPAN class=fcg>\s*([\s\S]*?)\s*</SPAN>"
        Dim htmlsrc As String = frmMain.WebBrowser1.Document.DomDocument.documentElement.InnerHTML
        Dim txt As String = String.Empty
        Dim tag As String = String.Empty
        For Each m As Match In Regex.Matches(htmlsrc, pattern)
            txt = m.Groups("text").Value.Replace(txt2highlight, "<span style=""background-color:#44F; color:#FFF"">" & txt2highlight & "</span>")
            tag = m.Value.Replace(m.Groups("text").Value, txt)
            htmlsrc = htmlsrc.Replace(m.Value, tag)
        Next

Open in new window

Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

nepaluzCommented:
1. How many matches do you get?

2. Try adding an iteration of the matches to XElement e.g

Dim J1 = Regex.Matches(htmlsrc, pattern)
Dim  xDoc As XDocument = XDocument.Parse(J1)
Dim sx1 = From kp In xDoc.Descendants Select kp.<span>.ToList

For Each q in sx1
  If q.Count = 0 Then Exit For
  txt = q(0).Value
Next

I am not sure what you are trying to achieve with the rest of your code inside the for statement .....
XK8ERAuthor Commented:
I am trying to match with this but all im getting is fcg>10

<\s*SPAN\s+[^>]*class\s*=[\s'" & "]*(?<word>[^" & "'\s]+)[^>]*>


<SPAN class=fcg>2 downloaded images</SPAN>

nepaluzCommented:
With code samples, please try to provide all definitions you are using to help us help you.

1. What is: txt2highlight ?

2. What evaluation do you get from:
a. txt = m.Groups("text").Value
b. tag = m.Value
XK8ERAuthor Commented:
all im looking for is to fix this regex.. thats all..


<\s*SPAN\s+[^>]*class\s*=[\s'" & "]*(?<word>[^" & "'\s]+)[^>]*>


I need it to match this "2 downloaded images"

<SPAN class=fcg>2 downloaded images</SPAN>
nepaluzCommented:
I gave you the solution to that:
Dim htmlsrc As String = frmMain.WebBrowser1.Document.DomDocument.documentElement.InnerHTML
Dim txt As String = String.Empty
Dim pattern As String = "<SPAN class=fcg>\s*([\s\S]*?)\s*</SPAN>"
Dim J1 = Regex.Matches(htmlsrc, pattern)
Dim  xDoc As XDocument = XDocument.Parse(J1)
Dim sx1 = From kp In xDoc.Descendants Select kp.<span>.ToList

For Each q in sx1
  If q.Count = 0 Then Exit For
  txt = q(0).Value
  Exit For
Next

txt is the value you are looking for (if there is only ONE <span class=fcg> in the document).

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nepaluzCommented:
I am actually fed-up with this. You can reference this site for more on Regex examples / suggested solutions.

http://regexlib.com/Search.aspx?k=html&c=-1&m=-1&ps=20
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.