Re: regex help
- From: Jerod Houghtelling <houghtelling@xxxxxxxxx>
- Date: Mon, 17 Sep 2007 09:09:52 -0700
On Sep 17, 8:58 am, Jesse Houwing <jesse.houw...@xxxxxxxxxxxxxxxx>
wrote:
Hello Jerod,
On Sep 17, 7:25 am, Jerod Houghtelling <houghtell...@xxxxxxxxx> wrote:
On Sep 17, 6:32 am, AVL <A...@xxxxxxxxxxxxxxxxxxxxxxxxx> 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 Houwing
jesse.houwing at sogeti.nl
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
.
- Follow-Ups:
- Re: regex help
- From: Jesse Houwing
- Re: regex help
- References:
- Re: regex help
- From: Jerod Houghtelling
- Re: regex help
- From: Jesse Houwing
- Re: regex help
- Prev by Date: Re: regex help
- Next by Date: Re: Com ports over bluetooth
- Previous by thread: Re: regex help
- Next by thread: Re: regex help
- Index(es):
Relevant Pages
|