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
sampath mekaPosted Dec 10, 2014, 11:27 AM
Wim SturkenboomPosted Dec 10, 2014, 2:58 AM
Sorry with your expression the code is not executing if i remove $ at end it is working but considering .csi,.ctr has output
[/quote]
Seems to work on my system (with $ included).
A little test program in C# (sorry, don't do VB)
static void Main(string[] args)
{
Regex re = new Regex("^.+[.][ch]$");
string[] filenames = new string[] {
"myname.c",
"myname.csi",
"myname.ctr",
"myname.hsi",
"myname.h",
"myname.htr"
};
for (int cnt = 0; cnt < filenames.Length; cnt++)
{
if (re.IsMatch(filenames[cnt]))
{
Console.WriteLine("* " + filenames[cnt]);
}
else
{
Console.WriteLine(" " + filenames[cnt]);
}
}
Console.ReadLine();
}
Result (matching files are prepended with '*')
* myname.c
myname.csi
myname.ctr
myname.hsi
* myname.h
myname.htr
sampath mekaPosted Dec 10, 2014, 1:48 AM
sampath mekaPosted Dec 10, 2014, 1:44 AM
Wim SturkenboomPosted Dec 10, 2014, 1:35 AM
Some like below should do the trick
^.+[.][ch]$
^ beginning of text
.+ anything, at least 1 character
[.] followed by dot
[ch] followed by c or h
$ end of text
[ch]$ can be read as c or h at end of text