惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Martin Fowler
Martin Fowler
L
Lohrmann on Cybersecurity
罗磊的独立博客
V
V2EX
人人都是产品经理
人人都是产品经理
腾讯CDC
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
aimingoo的专栏
aimingoo的专栏
D
Docker
云风的 BLOG
云风的 BLOG
B
Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Microsoft Azure Blog
Microsoft Azure Blog
C
Check Point Blog
IT之家
IT之家
S
Secure Thoughts
S
Security @ Cisco Blogs
博客园 - 聂微东
阮一峰的网络日志
阮一峰的网络日志
G
Google Developers Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
TaoSecurity Blog
TaoSecurity Blog
博客园_首页
雷峰网
雷峰网
博客园 - 三生石上(FineUI控件)
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
H
Heimdal Security Blog
Last Week in AI
Last Week in AI
Engineering at Meta
Engineering at Meta
D
DataBreaches.Net
J
Java Code Geeks
PCI Perspectives
PCI Perspectives
GbyAI
GbyAI
Help Net Security
Help Net Security
W
WeLiveSecurity
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
S
Schneier on Security
H
Hackread – Cybersecurity News, Data Breaches, AI and More
F
Full Disclosure
A
About on SuperTechFans
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Recorded Future
Recorded Future
C
CXSECURITY Database RSS Feed - CXSecurity.com
NISL@THU
NISL@THU
Hacker News: Ask HN
Hacker News: Ask HN
The Cloudflare Blog
Latest news
Latest news
The Last Watchdog
The Last Watchdog
Attack and Defense Labs
Attack and Defense Labs
T
The Blog of Author Tim Ferriss

博客园 - eaglet

HubbleDotNet 的注册码生成器 .net 下如何将文档文件(Word, Pdf等) 中的文本提取出来 NTCPMSG 开源高性能TCP消息发送组件 文件在不同文件系统间拷贝文件时间改变的问题 文件是否真的写入了磁盘? 如何自动延长 windows 2008 试用版的试用期 获取ALL USER 的特殊目录的类 i—比 i++ 快? 多线程环境下调用 HttpWebRequest 并发连接限制 HubbleDotNet+Mongodb 构建高性能搜索引擎--概述 C# 重启计算机的问题 HubbleDotNet 索引分词的测试方法和分词技巧 Windows 启动顺序详解 记录windows操作系统启动日志 C# 程序自动批量生成 google maps 的KML文件 通过 Windows 7 共享上网 正确理解 SqlConnection 的连接池机制 Windows 2008 server + IIS 7 设置身份模拟(ASP.NET impersonation) IIS 7.5 配置 FTP Passive 模式
文件名通配符匹配的代码
eaglet · 2013-01-31 · via 博客园 - eaglet

Windows 下可以用 * ? 作为通配符对文件名或目录名进行匹配。程序中有时候需要做这样的匹配,但.Net framework 没有提供内置的函数来做这个匹配。我写了一个通过正则进行匹配的方法。

 private static bool WildcardMatch(string text, string pattern, bool ignoreCase)
    {
        if (string.IsNullOrEmpty(pattern))
        {
            return true;
        }

        if (string.IsNullOrEmpty(text))
        {
            foreach (char c in pattern)
            {
                if (c != '*')
                {
                    return false;
                }
            }

            return true;
        }

        string regex = "^" + Regex.Escape(pattern).
                           Replace(@"\*", ".*").
                           Replace(@"\?", ".") + "$";

        if (ignoreCase)
        {
            Match match = Regex.Match(text, regex, RegexOptions.IgnoreCase);

            return match.ToString() == text;
        }
        else
        {
            Match match = Regex.Match(text, regex);

            return match.ToString() == text;
        }
    }