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

Wim SturkenboomRank #2,527 · 554 reputationPosted Dec 9, 2014, 9:58 PM EST
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
Wim SturkenboomRank #2,527 · 554 reputationPosted Dec 9, 2014, 8:35 PM EST
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
sampath meka90 reputationPosted Dec 9, 2014, 8:44 PM EST
sampath meka90 reputationPosted Dec 9, 2014, 8:48 PM EST
sampath meka90 reputationPosted Dec 10, 2014, 6:27 AM EST