zoukankan      html  css  js  c++  java
  • C# 实现文件文本的正则表达式查询

     1        static void QueryWithRegEx()
     2         {
     3             string startFolder = @"c:\program files\Microsoft Visual Studio 9.0\";
     4             IEnumerable<FileInfo> fileList = GetFiles(startFolder);
     5 
     6             Regex searchTerm = new Regex(@"Visual (Basic|C#|C\+\+|J#|SourceSafe|Studio)");
     7 
     8             var queryMatchingFiles = from file in fileList
     9                                      where file.Extension == ".htm"
    10                                      let fileText = System.IO.File.ReadAllText(file.FullName)
    11                                      let matches = searchTerm.Matches(fileText)
    12                                      where matches.Count > 0
    13                                      select new
    14                                      {
    15                                          name = file.FullName,
    16                                          matchedValues = from System.Text.RegularExpressions.Match match in matches
    17                                                          select match.Value
    18                                      };
    19         }
  • 相关阅读:
    畅销书排行榜
    阿里云大数据产品体系
    天然气收费管理系统的研究与实现随笔
    Web端实现RTC视频特效的解决方案
    从0搭建在线聊天室,只需4步!
    技术干货 | JavaScript 之事件循环(Event Loop)
    C++20 四大特性之一:Module 特性详解
    Android Flutter 多实例实践
    网易云信线上万人连麦技术大揭秘
    Python + Pytest 自动化框架的用例依赖实操
  • 原文地址:https://www.cnblogs.com/dingshouqing/p/2392186.html
Copyright © 2011-2022 走看看