I wrote a simple script, using VBA. (I need to optimize some work with excel).
First question about Regex:
As I said before, I used VBA.
Simple task: get a match of pattern and capture the submatches.
my code is:
Dim ResStr as Object
Dim LastStr as Object
Dim RE as Object
Set RE = CreateObject("vbscript.regexp") 'create a regex
With RE
.MultiLine = False 'm-key
.Global = False 'g-key
.IgnoreCase = False 'i-key
.Pattern = "[<]TD\s+class=gm[>](\d+\.\d+)[<][/]TD[>]" 'tag
End With
Set ResStr = RE.Execute(StrDollar) 'use regex
Set LastStr = ResStr(0).SubMatches 'get submatch
How do I get the LAST match and LAST submatch? (length-property?)
Second question about Dir function:
How do I filter the files?
I saw this code on msdn:
' Display the names in C:\ that represent directories.
MyPath = "c:\" ' Set the path.
MyName = Dir(MyPath, vbDirectory) ' Retrieve the first entry.
Do While MyName <> "" ' Start the loop.
' Use bitwise comparison to make sure MyName is a directory.
If (GetAttr(MyPath & MyName) And vbDirectory) = vbDirectory Then
' Display entry only if it's a directory.
Debug.WriteLine(MyName)
End If
MyName = Dir() ' Get next entry.
Loop
If (GetAttr(MyPath & MyName) And vbDirectory) = vbDirectory Then – stop ‘msdn-guy’! are you kidding? is it ONLY one method?
Is there any possible way to make normal filter, not this tremendous-line method?
To get all matches, submatches, length etc you would use something like this – I have added a working example with a simpler pattern to demonstrate (ie match a sequences of numbers with then a non-number)
You should
Testyour regexp before presuming a match has been found to avoid erros