XK8ER
asked on
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?
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?
NOTE: The rResult is actually the WebPageResult I declared above!
ASKER
for some reason I am getting this error
>>String cannot be of zero length.
tag = m.Value.Replace(m.Groups(" text").Val ue, txt)
>>String cannot be of zero length.
tag = m.Value.Replace(m.Groups("
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
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 .....
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 .....
ASKER
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>
<\s*SPAN\s+[^>]*class\s*=[
<SPAN class=fcg>2 downloaded images</SPAN>
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
1. What is: txt2highlight ?
2. What evaluation do you get from:
a. txt = m.Groups("text").Value
b. tag = m.Value
ASKER
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>
<\s*SPAN\s+[^>]*class\s*=[
I need it to match this "2 downloaded images"
<SPAN class=fcg>2 downloaded images</SPAN>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
http://regexlib.com/Search.aspx?k=html&c=-1&m=-1&ps=20
Dim WebPageResult As string
Dim RegexResult = Regex.Match(rResult, "<SPAN class=fcg>\s*([\s\S]*?)\s*
From there you can parse the result to retrieve the string value.
(ps. Could you mark the question you posted here: https://www.experts-exchange.com/questions/26705597/vb-net-match-numbers.html?cid=1576