Hello All,
My question is i have following file names where it process based on the extension type using regular expression only.
myname.c
myname.csi
myname.ctr
myname.hsi
myname.h
myname.htr
For the above strings if we apply regular expression the output should be
myname.c
myname.h
I want only file name with extension .c and .h only
Thanks & Regards,
Sampath
VulpesPosted Dec 10, 2014, 11:57 AM
This VBS script is working OK for me:
Dim a
a = Array("myname.c","myname.csi","myname.ctr","myname.hsi","myname.h","myname.htr")
Set reg = New RegExp
reg.Multiline = False
reg.Global = False
reg.Pattern = "^.+[.][ch]$"
For Each s in a
Set mc = reg.Execute(s)
For Each m in mc
Wscript.echo m.Value
Next
Next
The output is:
myname.c
myname.h
sampath mekaPosted Dec 10, 2014, 11:43 PM
Wim SturkenboomPosted Dec 10, 2014, 12:28 PM
But OK, here is my first program in VB
Sub Main()
Dim re As New Regex("^.+[.][ch]$")
Dim filenames() = {
"myname.c",
"myname.csi",
"myname.ctr",
"myname.hsi",
"myname.h",
"myname.htr"}
For Each name As String In filenames
Console.Write(name & " ")
Console.WriteLine(re.IsMatch(name))
Next
Console.ReadLine()
End Sub