Question Wrong use of regex?

littlebigman

Well-known member
Joined
Jan 5, 2010
Messages
75
Programming Experience
Beginner
Hello

I can't figure out why the regex object fails to find a pattern in a web page, although it's pretty simple and a test shows that the pattern is OK. Could it be that I misunderstood how VB's regex object works?

Here's the HTML input:
VB.NET:
<table cellspacing="0" cellpadding="0" id="oft">
	<thead>
		<tr>
...			
	    
	</tbody>
</table>

And here's the VB code:
VB.NET:
Dim goodstuff As Regex = New Regex("^<table cellspacing=""0"" cellpadding=""0"" id=""oft"">(.+?)</table>", RegexOptions.Singleline)
Dim m As Match

m = goodstuff.Match(Input)
If m.Success Then
	Me.RichTextBox1.AppendText(m.Groups(1).Value)
Else
	Me.RichTextBox1.AppendText("Table not found in www")
End If

Thanks for any help.
 
Maybe that is not all the input? The ^ character matches start of input string. It's a match if the string starts like that.

Usually though, regex is not a good option for parsing the html document tree, better options includes using WebBrowser control or a library like Html Agility Pack.
 
Back
Top