正则匹配百度结果

前端之家收集整理的这篇文章主要介绍了正则匹配百度结果前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

重点是先抓取<td>里的内容,其它的就好说了:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;

namespace ReadFile
{
    class Program
    {
        static void Main(string[] args)
        {
            string FilePath = @"E:\vs\bd.txt";
            StreamReader sr = new StreamReader(FilePath,Encoding.GetEncoding("UTF-8"));
            string FileContent = sr.ReadToEnd();
            FileContent = Regex.Replace(FileContent,"[\r\n\t]+","");
            string PatternTable = "(?i)<table class=\"result\"[^>]*?>(?:(?!</?table>)[\\s\\S])*?</table>";
            string PatternBlock = "<td class=\"c-default\" >(?:(?!</?td>)[\\s\\S])*?</td>";
            MatchCollection mc = Regex.Matches(FileContent,PatternBlock,RegexOptions.Multiline);
            Match mm = Regex.Match(FileContent,RegexOptions.Multiline);
            //Debug.WriteLine(mm.Groups.Count);
            foreach (Match mat in mc)
            {
                Console.WriteLine("================================================");
                Console.WriteLine(mat.Value);
            }

            Console.Read();
        }
    }
}

猜你在找的正则表达式相关文章