0

http://regexr.com/3cs9n

as you can see on this link my regex code works well. But same code in VB.NET having problem. As you can see on regexr website i must catch 25 matches. But VB.NET is returns 12 matches. (I see 2 matches when i look into a match).

<tr><td align=LEFT><A HREF="/satellite/?s=41315">BEIDOU M3-S</A></td><td align=CENTER>41315</td><td align=CENTER>2016-006A</td><td align=CENTER><a href="/browse/?y=2016&m=2">February 1, 2016</a></td><td align=CENTER>783</td><td align=CENTER><button class="sButton" onclick="javascript:window.location.href='/?s=41315'">TRACK IT</button></td></tr>
<tr bgcolor="#F4F4F4"><td align=LEFT><A HREF="/satellite/?s=40938">BEIDOU I2-S</A></td><td align=CENTER>40938</td><td align=CENTER>2015-053A</td><td align=CENTER><a href="/browse/?y=2015&m=9">September 29, 2015</a></td><td align=CENTER>1436.2</td><td align=CENTER><button class="sButton" onclick="javascript:window.location.href='/?s=40938'">TRACK IT</button></td></tr>

this is 1 match on vb.net. Actually must be 2 matches (seems like on regexr).

thanks inadvance

MGR
  • 167
  • 1
  • 11

1 Answers1

0

I think maybe the problem is that your matching pattern contains some doublequotes symbols and you're not handling this..

So I edited your pattern, tried the following code, and it returns two matches:

Dim ptrn As String = "<tr( bgcolor=""#F4F4F4""|)><td align=LEFT><A HREF=""(.*?)"">(.*?)<\/A><\/td><td align=CENTER>(.*?)<\/td><td align=CENTER>(.*?)<\/td><td align=CENTER><a href=""(.*?)"">(.*?)<\/a><\/td><td align=CENTER>(.*?)<\/td><td align=CENTER><button class=""sButton"" onclick=""(.*?)"">TRACK IT<\/button><\/td><\/tr>"
MessageBox.Show(Regex.Matches(txtInput.Text, ptrn).Count.ToString & " matches found")

Screenshot:

enter image description here

Hope this helps :)

  • Thanks. solved my problem but i can't understand. how internet shows 25 matches if my pattern is wrong :S – MGR Feb 24 '16 at 13:16
  • It's not wrong, it just contains characters (") that VB uses as a start and end 'tag' for strings.. you may also put your pattern (as it is in 'regexr.com') in a textbox (e.g: txtPattern) and call: `Regex.Mathes(txtInput.Text, txtPattern.Text)` to make sure it's working – 41686d6564 stands w. Palestine Feb 24 '16 at 13:35