- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
在下面的 C# 方法中,我知道 Directory.GetFileNsmes() 会返回文件列表。而且,我可以添加有效的 Where contains(contact) 。然而,对于我的生活,我无法确定为什么 searchPatter.IsMatch() 无法找到文件。我测试了 http://regexpal.com/ 中的模式它如预期的那样 qorks。 namePattern 是 "^\d{3}(.*).pdf"并且应该有一个匹配项。
public static List<string> GetFileNames(string pathName, string namePattern, string contact)
{
var searchPattern = new Regex(namePattern, RegexOptions.IgnoreCase);
var files = Directory.GetFiles(pathName).Where(f => searchPattern.IsMatch(f));
//.Where(f => f.Contains(contact));
return files.ToList();
}
如果这已经在某处得到解答,请告诉我,但我找不到它。我认为这非常简单直接。
最佳答案
Directory.GetFiles
将返回填充文件路径,即 Drive\Directory\File.ext
。这就是为什么你的模式似乎不匹配。您只需要 FileName
作为主题。试试这个
var files = Directory.GetFiles(pathName)
.Where(f => searchPattern.IsMatch(Path.GetFileName(f)));
关于c# - .net linq with regex ismatch in where,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21311340/
我正在使用 lodash用于比较以下两个对象: obj1 = { "_id": "57767", "Re": { "PropertyTypes": [
我为缓存扩展编写了测试。我想按模式从缓存中删除。 a) 在这个例子中测试失败 [Test] public void Should_found_by_pattern() {
我知道有很多类似的问题,但这是特定于我的正则表达式的。我正在尝试查看字符串中是否有任何 html。 Regex tagRegex = new Regex(@"]+)[^>]*>.*?") if(tag
我正在尝试查找遵循“char 'h' 后跟一位或多位数字”模式的文件,例如 h0、h1、h22 但我也得到“h22 cco”和 hhh0 如何解决这个问题 files = new List((from
我正在对一些转义字符串进行匹配比较: Regex.IsMatch("\\Application.evtx", "DebugLogs\\ConfigurationServices.log"); 我不明白
我一直在努力解决一个奇怪的问题。我有一组正则表达式模式,用于匹配和阻止针对我网站的黑客攻击。 有一种特定的模式非常常见,但是由于某种原因,我针对它的模式并不总是与传入的 url 匹配。 如果我手动单步
我有一个列表,例如: Type [data] Device Type [data] Pin type [data] 我试图只搜索类型 [data] 而不是设备类型或 Pin 类型。请注意 [data]
我尝试使用正则表达式来检查字符串是否仅包含:0-9、A-Z、a-z、\、/或 -。我使用了 Regex validator = new Regex(@"[0-9a-zA-Z\-/]*"); 无论我引入
我有一个小函数,用于在用户取消编辑后验证 StringGrid 中的列。 void validateColumn(int column, const UnicodeString regexp, TSt
谁能告诉我以下提到的正则表达式中的错误: 正则表达式:@"^(tcm:\d+-\d+)" 输入字符串:tcm:12-123a6 问题:据我所知,\d 应该只匹配数字。输入字符串中有'a'。它仍然匹配输
我有以下代码可以正常工作,但我需要用变量替换站点地址... string url = HttpContext.Current.Request.Url.AbsoluteUri; // Get the
我有以下代码, filter="search.ismatch('Paris\-l''Hopital*', 'DestinationAddress/City', 'full', 'all')" 此过滤器
我期待下面的代码返回 Chris Davis 和 Mike Trout。它只返回 Mike Trout。是否无法匹配多个值?请记住,我最终需要匹配 30 多个值。我也尝试过使用indexOf,但它的扩
这个问题已经有答案了: Regex doesn't work in String.matches() (9 个回答) 已关闭 5 年前。 原始正则表达式:[v]\d+?\.\d 捕获字符串中的“v{N
我有一个很长的文本 (50-60 KB),我需要针对它运行几个正则表达式(总共大约 100 个规则)。然而,这太慢了,以至于它基本上不起作用。 我所做的只是围绕规则创建了一个循环,其中每个规则执行 R
这是我的代码的摘录: string[] myStr = { " Line1: active 56:09 - tst0063, tst0063",
我正在使用 new Regex("(?m)^\S+ [A-Z]{1,3}$").IsMatch(sStringToCheck) 检查多行字符串。 我的问题是,它似乎只验证字符串的最后一行。 此列表通过
是的,这是另一个 .net 正则表达式问题:)(请原谅导致实际问题的长篇华夫饼) 我允许用户使用简单的日期/时间宏来快速输入日期(他们不需要日期选择器) 例如他们可以输入: d +1d -2h 这将为
我编译的代码: namespace TestRegExp { class Program { static void Main(string[] args)
我正在尝试使用以下正则表达式匹配可以包含任意数量的数字字符或小数点的字符串: ([0-9.])* 下面是一些用于测试正则表达式的 C# 代码: Regex regex = new Regex("([0
我是一名优秀的程序员,十分优秀!