如何在VBS中搜索带部分通配符的文件

时间:2010-07-20 05:36:45

标签: vbscript

我需要搜索文件名AM * GQ,其中*是序列,例如344

我能做这个vbs吗?

2 个答案:

答案 0 :(得分:1)

您可以使用instr()

答案 1 :(得分:1)

正则表达式应该有效。

pattern = "[A][M][0-9]*[G][Q].*"
stringToSearch = "AM432GQ.txt"
MsgBox RegExTest(pattern,stringToSearch)

Function RegExTest(pattern, stringToSearch)
   Dim regEx, Match, Matches   ' Create variable.
   Set regEx = New RegExp   ' Create a regular expression.
   regEx.Pattern = pattern   ' Set pattern.
   regEx.IgnoreCase = True   ' Set case insensitivity.
   regEx.Global = True   ' Set global applicability.
   Set Matches = regEx.Execute(stringToSearch)   ' Execute search.
   For Each Match in Matches   ' Iterate Matches collection.
      RetStr = RetStr & "Match found at position "
      RetStr = RetStr & Match.FirstIndex & ". Match Value is '"
      RetStr = RetStr & Match.Value & "'." & vbCRLF
   Next
   RegExTest = RetStr
End Function