I'm slightly confused as to how RegExp works. I'm very happy using it to search for strings using something like notepad++, however I'm now trying to search through a string in VBScript and the RegExps that work in notepad++ don't seem compatible with VBScript. I incorrectly presumed that regexp was a standard of sorts. Anyway.
The string I'm trying to search through is:
"kcabllaCsrevirD - ) 0x0 = TLUSERH ( 'FNI.TRWTS\049BE47424A6-2898-65A4-3538-602212F0\#\$1#40C0010B$gkPrevirD_O_\10RPAFJUOS\\' egakcaP revirD 8202=DI
I'm trying to identify:
FNI.TRWTS\
Using notepad++, and trying to follow the sytax as described in this MSDN article I've come up with:
.*?fni\..*?\\
Can anyone point me in the right direction here? I have other regexps working in VB so am fairly happy that my VB is OK.
For some background on the string - I've reversed a line of text from a DISM log and am trying to extract the driver name, so looking to pick out fni.* and then reverse it back to *.inf. The reason I'm doing it this way is whilst I can get regexps to search non greedy (.*?) I can't seem to find a method of matching last first.
Set objFso = CreateObject("Scripting.FileSystemObject")
Set TxtDismLog = objFSO.GetFile("C:\Windows\SysWow64\CCM\Logs\dism.log").OpenAsTextStream(1,-2)
Set TxtDriverOutput = objFSO.CreateTextFile("C:\Program Files\Sam\drivers.log", 8, True)
Set objRegEx = CreateObject("VBScript.RegExp")
Set objRegEx2 = CreateObject("VBScript.RegExp")
objRegEx.Global = True
objRegEx.IgnoreCase = True
objRegEx.Pattern = "Found \d driver package"
objRegEx2.Global = True
objRegEx2.IgnoreCase = True
objRegEx2.Pattern = "\bfni\.[^\\]*\\"
txtDriverOutput.WriteLine Now() & Chr(32) & "Begin DISM Driver Scan"
Do While TxtDismLog.AtEndOfStream <> True
txtline = txtDismLog.ReadLine
If objRegEx.Test(txtline) Then
h = InStr(txtline,"Found")
i = Mid(txtline,h+6,1)
Do While i <> 0
i = i - 1
txtline = txtDismLog.ReadLine
txtlinebwd = StrReverse(txtline)
regfindbwd = objRegEx2.Execute(txtlinebwd)
regfind = StrReverse(regfindbwd)
txtDriverOutput.WriteLine regfind
Loop
End If
Loop
fni.? BTW, which tag is correct: vb.net or vbscript? Please show your code.fni\.[^\\]*\\. If you use it with a case-insensitive flag, it should work even when multiple values appear in the same string (Global = True with your RegExp is OK then). I will post it.