regex help

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hi,
i'm a new bie to regular expressions..
i'm trying to see if a string ends with teh below
pattern \filename.xls or \filename.xlsx...

I've used the @"\\[\w|\W]+\.xls" pattern but's it's
matching hte below string
d:\sample\.xls....

can someone help me out with teh correct pattern
 
hi,
i'm a new bie to regular expressions..
i'm trying to see if a string ends with teh below
pattern \filename.xls or \filename.xlsx...

I've used the @"\\[\w|\W]+\.xls" pattern but's it's
matching hte below string
d:\sample\.xls....

can someone help me out with teh correct pattern

You could try @"\\[\w|\W]+\.xls$" if it is at the end of the string.
You could also use the System.IO.FileInfo class...

FileInfo fInfo = new FileInfo(@"\My Documents\Filename.xls");
if(fInfo.Extension.ToLower() == "xls")
{
...
}

Jerod
 
hi,
i'm a new bie to regular expressions..
i'm trying to see if a string ends with teh below
pattern \filename.xls or \filename.xlsx...
I've used the @"\\[\w|\W]+\.xls" pattern but's it's
matching hte below string
d:\sample\.xls....
can someone help me out with teh correct pattern

You could try @"\\[\w|\W]+\.xls$" if it is at the end of the string.
You could also use the System.IO.FileInfo class...

FileInfo fInfo = new FileInfo(@"\My Documents\Filename.xls");
if(fInfo.Extension.ToLower() == "xls")
{
...

}

Jerod

Sorry didn't entirely read your question correctly. You might want to
try @"\\[\w}\W]+\.xls[?x]" or @"\\[\w}\W]+\.xls[?x]$" depending if you
are reading a single line or multiple lines at a time.

Jerod
 
Hello Jerod,
hi,
i'm a new bie to regular expressions..
i'm trying to see if a string ends with teh below
pattern \filename.xls or \filename.xlsx...
I've used the @"\\[\w|\W]+\.xls" pattern but's it's
matching hte below string
d:\sample\.xls....
can someone help me out with teh correct pattern
You could try @"\\[\w|\W]+\.xls$" if it is at the end of the string.
You could also use the System.IO.FileInfo class...

FileInfo fInfo = new FileInfo(@"\My Documents\Filename.xls");
if(fInfo.Extension.ToLower() == "xls")
{
...
}

Jerod
Sorry didn't entirely read your question correctly. You might want to
try @"\\[\w}\W]+\.xls[?x]" or @"\\[\w}\W]+\.xls[?x]$" depending if you
are reading a single line or multiple lines at a time.

Jerod

Jerod, either these expresisons got mangled by your newsreader or they are
incorrect.

[^\\]\.xlsx?$

is the correct expression to check for a file that ends with xls or xlsx
and had something other than a backslash in front of the .

I'd also go with the FIleInfo or System.IO.Path class as a better solution
for this problem.
 
Hello Jerod,


hi,
i'm a new bie to regular expressions..
i'm trying to see if a string ends with teh below
pattern \filename.xls or \filename.xlsx...
I've used the @"\\[\w|\W]+\.xls" pattern but's it's
matching hte below string
d:\sample\.xls....
can someone help me out with teh correct pattern
You could try @"\\[\w|\W]+\.xls$" if it is at the end of the string.
You could also use the System.IO.FileInfo class...
FileInfo fInfo = new FileInfo(@"\My Documents\Filename.xls");
if(fInfo.Extension.ToLower() == "xls")
{
...
}
Jerod
Sorry didn't entirely read your question correctly. You might want to
try @"\\[\w}\W]+\.xls[?x]" or @"\\[\w}\W]+\.xls[?x]$" depending if you
are reading a single line or multiple lines at a time.

Jerod, either these expresisons got mangled by your newsreader or they are
incorrect.

[^\\]\.xlsx?$

is the correct expression to check for a file that ends with xls or xlsx
and had something other than a backslash in front of the .

I'd also go with the FIleInfo or System.IO.Path class as a better solution
for this problem.

Jesse,

Thanks for correcting my error! Your regular expression is correct. I
was trying to use the posters original expression, but incorrectly
referenced the x? as [?x]. Hadn't had any caffeine yet this
morning. ;)

Thanks again,
Jerod
 
Hello Jerod,
Hello Jerod,
On Sep 17, 7:25 am, Jerod Houghtelling <[email protected]>
wrote:


hi,
i'm a new bie to regular expressions..
i'm trying to see if a string ends with teh below
pattern \filename.xls or \filename.xlsx...
I've used the @"\\[\w|\W]+\.xls" pattern but's it's
matching hte below string
d:\sample\.xls....
can someone help me out with teh correct pattern
You could try @"\\[\w|\W]+\.xls$" if it is at the end of the
string. You could also use the System.IO.FileInfo class...

FileInfo fInfo = new FileInfo(@"\My Documents\Filename.xls");
if(fInfo.Extension.ToLower() == "xls")
{
...
}
Jerod

Sorry didn't entirely read your question correctly. You might want
to try @"\\[\w}\W]+\.xls[?x]" or @"\\[\w}\W]+\.xls[?x]$" depending
if you are reading a single line or multiple lines at a time.

Jerod
Jerod, either these expresisons got mangled by your newsreader or
they are incorrect.

[^\\]\.xlsx?$

is the correct expression to check for a file that ends with xls or
xlsx and had something other than a backslash in front of the .

I'd also go with the FIleInfo or System.IO.Path class as a better
solution for this problem.
Jesse,

Thanks for correcting my error! Your regular expression is correct. I
was trying to use the posters original expression, but incorrectly
referenced the x? as [?x]. Hadn't had any caffeine yet this
morning. ;)

I know that feeling (though it's usually just after lunch ;)).
 
Back
Top