Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex VB.Net搜索与正则表达式匹配的文件_Regex_Vb.net - Fatal编程技术网

Regex VB.Net搜索与正则表达式匹配的文件

Regex VB.Net搜索与正则表达式匹配的文件,regex,vb.net,Regex,Vb.net,嗨,我有一个非常基本的问题,我完全找不到答案。我想在给定目录中搜索文件REGEX匹配项。我尝试过各种迭代,但都不管用。我的正则表达式是“*_Ch[0-9]+.sgm”,它应该可以工作。我的文件名为“Bld1_Ch1.sgm”,并进行迭代 我得到的错误是“System.IO.DirectoryNotFoundException:'找不到路径'C:\Test\06-GCS Bursting Script\到33D1-8-2-2-2 RAMTS FI\Bld1'的一部分。” 谢谢你的耐心和帮助。 马克

嗨,我有一个非常基本的问题,我完全找不到答案。我想在给定目录中搜索文件REGEX匹配项。我尝试过各种迭代,但都不管用。我的正则表达式是“*_Ch[0-9]+.sgm”,它应该可以工作。我的文件名为“Bld1_Ch1.sgm”,并进行迭代

我得到的错误是“System.IO.DirectoryNotFoundException:'找不到路径'C:\Test\06-GCS Bursting Script\到33D1-8-2-2-2 RAMTS FI\Bld1'的一部分。”

谢谢你的耐心和帮助。 马克辛


我能用这个代码让它工作!谢谢大家的帮助

    Dim files = Directory.GetFiles(path, "*.sgm")

    Dim rx = New Regex(".*_Ch\d\.sgm") ' or Dim rx = new Regex(".*_v[0-9]\.pdf")

    For Each file In files
        If rx.IsMatch(file) Then
            ' do something with the file
            MsgBox(file)
        End If
    Next file

尝试在regex的开头使用
*
而不是
*
?另外,最好转义点并将正则表达式写成
*\u Ch[0-9]+\.sgm
我得到一个非法字符错误看起来您可能必须转义\as\\或者您可以试试这个正则表达式吗
*\u Ch[0-9]+[.sgm
?问题的全部原因是该方法不支持正则表达式。。。请查看详细信息并阅读“搜索模式”部分。您仍然可以使用正则表达式,例如:
Dim reg As regex=New regex(“_Ch[0-9]+.sgm”)Dim files=Directory.GetFiles(yourPath)。其中(Function(path)reg.IsMatch(path)).ToList()
    Dim files = Directory.GetFiles(path, "*.sgm")

    Dim rx = New Regex(".*_Ch\d\.sgm") ' or Dim rx = new Regex(".*_v[0-9]\.pdf")

    For Each file In files
        If rx.IsMatch(file) Then
            ' do something with the file
            MsgBox(file)
        End If
    Next file