wolfh3art Posted August 29, 2006 Share Posted August 29, 2006 hi,Could someone help me discover the RegExp for KB1234567.exeI want to check if the first 2 chars are "KB", the following 6 chars are between [0-9] and the last four are ".exe".I only discovery how to check in the beginning or in the end, i don't know how to make the 3 conditions.Sorry my english,thanks Link to comment Share on other sites More sharing options...
Yzöwl Posted August 29, 2006 Share Posted August 29, 2006 What have you got so far? and will either of these help!KB\d{6}\.exeorKB[0-9]{6}\.exe Link to comment Share on other sites More sharing options...
gunsmokingman Posted August 29, 2006 Share Posted August 29, 2006 (edited) You could use a inStr to filter out what you wantExample Filter Out One String ElementSave As InstrDemo_1.vbsDim MyArray, StrArray, Report'/-> Array Of Names MyArray = Array("ZZ_SomeApp.exe", "Unknown.Dll","FolderApp.exe", "NewPaintApp.exe", "KB1234567.exe",_ "SomeThing.Dll", "CoolApp.exe", "TheTextDoc.txt")'/-> For Each Loop For The Array MyArray For Each StrArray In MyArray If InStr(StrArray,"KB") Then '-> Filter Out KB In The Varible StrArray Report = Report & vbCrLf &_ " --------------------------------------------------------------------------- " & vbcrlf &_ "Correct File " & vbTab & Chr(187) & Space(3) & StrArray & vbCrLf &_ " --------------------------------------------------------------------------- " Else Report = Report & vbCrLf & "Wrong File " & vbTab & Chr(187) & Space(3) & StrArray End If Next '/-> Report The Correct And Wrong MsgBox Report, 0 + 32 + 4096, "InStr Report"Example Filter Out Two String ElementSave As InstrDemo_2.vbsDim MyArray, StrArray, Report'/-> Array Of Names MyArray = Array("ZZ_SomeApp.exe", "Unknown.Dll","FolderApp.exe", "NewPaintApp.exe", "KB1234567.exe",_ "SomeThing.Dll", "CoolApp.exe", "TheTextDoc.txt")'/-> For Each Loop For The Array MyArray For Each StrArray In MyArray If InStr(StrArray,".exe") Then '-> Filter Out .exe In The Varible StrArray If InStr(StrArray,"KB") Then '-> Filter Out KB In The Varible StrArray Report = Report & vbCrLf &_ " --------------------------------------------------------------------------- " & vbcrlf &_ "Correct File " & vbTab & Chr(187) & Space(3) & StrArray & vbCrLf &_ " --------------------------------------------------------------------------- " Else Report = Report & vbCrLf & "Wrong File " & vbTab & Chr(187) & Space(3) & StrArray End If End If Next '/-> Report The Correct And Wrong MsgBox Report, 0 + 32 + 4096, "InStr Report" Edited August 29, 2006 by gunsmokingman Link to comment Share on other sites More sharing options...
jdoe Posted August 29, 2006 Share Posted August 29, 2006 B) Const test = "KB1234567.exe"Dim strFileNameDim lngKbNumberstrFileName = testIf UCase(Left(strFileName,2)) = "KB" Then If UCase(Right(strFileName,4)) = ".EXE" Then On Error Resume Next lngKbNumber = CLng(Mid(strFileName,3,InStrRev(strFileName,".")-2)) On Error Goto 0 If Err = 0 Then 'Your code here End If End IfEnd If Link to comment Share on other sites More sharing options...
wolfh3art Posted August 30, 2006 Author Share Posted August 30, 2006 What have you got so far? and will either of these help!KB\d{6}\.exeorKB[0-9]{6}\.exethanks to all for the examples, this is what i was looking for ("kb[0-9]{6}.exe").I was using complex syntax and vbscript also uses simple... like this one.Dim objRegExpSet objRegExp = New RegExp objRegExp.Pattern = "kb[0-9]{6}.exe" objRegExp.IgnoreCase = FalseDim strVariable 'strVariable = "kb987653.exe" strVariable = "kb98763.exe" If objRegExp.Test( strVariable ) Then wscript.echo "Correct File" else wscript.echo "InCorrect File" End If Link to comment Share on other sites More sharing options...
Yzöwl Posted August 31, 2006 Share Posted August 31, 2006 I still think that you should be using the syntax I gaveKB[0-9]{6}\.exethe 'backslash' escapes the period, (which matches any printable or nonprintable character). Your current implementation should technically match KB123456jexe. I know that filename is not a likely one to come accross however it is still a possibility. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now