How to search for file with partial wildcard in VBS
I need to search for filename AM*GQ, where * is sequence eg 34开发者_StackOverflow中文版4
Can i do this vbs?
you can use instr()
Regular Expressions should work.
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
精彩评论