|
string htmlSource = "asdf<td class=\"hebrew2\" valign=\"top\">123</td>asdf<td class=\"hebrew2\" valign=\"top\">看老婆</td><td class=\"hebrew2\" valign=\"top\">456</td>asdf<td class=\"hebrew2\" valign=\"top\">上课了</td>asdfsadf"; Regex reg = new Regex("<td\\s+class=\"hebrew2\".*?>(?<val>.*?)</td>"); var ms = reg.Matches(htmlSource); for (int i = 0; i < ms.Count; i++) { Console.WriteLine(ms[i].Groups["val"].Value); }
推荐一个解析HTML的利器,AngleSharp。
<td[^<]*class="hebrew2"[^<]*>.*?</td>