This question has already been answered:

I decided to write a dumper Storis (portal with stories)

On the story page like this:

<h1 id="story_title">{ИМЯРАССКАЗА} <span class="vote"> 

The code is:

  storyid++; listBox1.Items.Add("Checking story: " + storyid + ".."); currStoryHTML = getHTML("http://site/story/" + storyid); if (currStoryHTML == "404NOTFOUND") return; Match match = Regex.Match(currStoryHTML, @"(?<=<<h1 id=" + "\"" + "story_title" + "\"" + ">>)(.*)(?=<span class=" + "\"" + "vote" + "\"" + ">)"); if (match.Success) { listBox1.Items.Add("Story with ID: " + storyid + " have name: " + match); } else { listBox1.Items.Add("Story with ID: " + storyid + " do not have name OR invalid.."); return; } 

It doesn't matter if the story exists. Always math.Success = false Can you help?

Reported as a duplicate by the participants andreycha , Pavel Mayorov , DeKaNszn , user31688, PashaPash 29 Apr '15 at 9:29 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

Transferred from meta.ru.stackoverflow.com Apr 14 '15 at 14:16 .

This question was originally posted on the discussion forum, support and innovations for the site programmers.

  • 7
    One of the greatest commandments of a programmer is to never parse HTML in regular sections if your brains are dear to you. But in general, why do you have <<h1 , and not <h1 ? - Mints97 2:19 pm
  • 3
    HTML is not parsed by regular expressions. To parse and extract data, use the Html Agility Pack: htmlagilitypack.codeplex.com - andreycha
  • Thank you all. The issue is resolved. - AGrief
  • four
    Classic link on the topic (should someone post it?) - VladD
  • Preview back .. Why? Put brackets and take the right group. - Qwertiy

1 answer 1

Never!! it is not necessary to parse Html regular expressions, for parsing Html there is a library HtmlAgility Pack

  • You repeated the comment on April 14th, actually. - VladD
  • There were comments and not answers - Sam_Fisher
  • one
    Perhaps. But if you give the answer, maybe it is worth giving an approximate code? - VladD