I have this program:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Text.RegularExpressions;
using System.IO;
using System.Net;
namespace Reviews_browser_test
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(enter good, that u want to find: ");
string tovar = Console.ReadLine();
string page = "http://www.ulmart.ru/search?string=&rootCategory=&sort=6";
page = page.Insert(35, tovar); // inserts good's id into url
HttpWebRequest site = (HttpWebRequest)WebRequest.Create(page);
HttpWebResponse response = (HttpWebResponse)site.GetResponse();
Stream dataStream = response.GetResponseStream();
StreamReader read = new StreamReader(dataStream);
String data = read.ReadToEnd();
Console.WriteLine(data);
System.IO.File.WriteAllText("ulmart.html", data);
Console.ReadKey();
Match m;
string pattern = "<span[^>]*?>[0-9]{4,10}</span>";
m = Regex.Match(data, pattern);
while (m.Success)
{
Console.WriteLine("Found an id " + m.Groups[1] + " at string "+ m.Groups[1].Index);
m = m.NextMatch();
}
Console.ReadKey();
}
}
}
And I want to get all id numbers from the html file. But i don't know, why using this regex it doesn't find anything, while notepad++ finds each id fine. The example of html string, that should be found, using this regex:
<span class="num">3609304</span>
Where is my mistake?

m.Groups[1], it is empty as you do not have any capturing group in your regex. You can use<span[^>]*?>([0-9]{4,10})</span>and access the value withm.Groups[1].Value. However, you will be safer using an HTML parser relying on XPath to select exact elements you need rather than trying it the hard way with regex. Are you trying to get inner text of allspantags withclass="num"?spanelements with the text you are looking for on that page.<span class="num">3609304</span>