Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 42457

VS 2010 regex help - first occurance

$
0
0
I am trying to get so it searches for just one row and returns the value. Right now my regex isn't working at all but guessing because it's not looking at first occurance.

How do I write the regex to find the first <tr><td>Description</td><td></td></tr>?

HTML Code:

<tr style="background-color:#EFF3FF;">    <td style="background-color:#DEE8F1;font-weight:bold;">Item</td><td>BOX123</td>    </tr><tr style="background-color:White;">    <td style="background-color:#DEE8F1;font-weight:bold;">Description</td><td>Box 1 with blah blah</td>    </tr><tr style="background-color:#EFF3FF;">    <td style="background-color:#DEE8F1;font-weight:bold;">Color</td><td>White</td>    </tr><tr style="background-color:White;">    <td style="background-color:#DEE8F1;font-weight:bold;">Quantity</td><td>4</td>    </tr>
Code:

Function GetItem(ByVal sHTML As String, ByVal sLabel As String) As String
        Dim options As RegexOptions = RegexOptions.IgnoreCase Or RegexOptions.Multiline
        Dim re As Regex = New Regex("<tr style="".*"">    <td style="".*"">" & sLabel & "<\/td><td>(?<returnval>.*)<\/td>    <\/tr>", options)
        Dim sRetVal As String = ""

        Dim mc As MatchCollection = re.Matches(sHTML)
        For Each m As Match In mc
            sRetVal = m.Groups("returnval").Value
        Next
        Return sRetVal
    End Function


Viewing all articles
Browse latest Browse all 42457


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>