need help on regex

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
 
J

Jesse Houwing

Hello AVL,
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

The reason why it matches is quite easily explained.

the middle part of your expression [\w\W] matches any character. So this
will always match anything up to .xls at the end.

You can solve this issue with regular expresions with the following expression:

[^\\]\.xlsx?$

Though it may be even easier to use the System.IO.Path class and use it's
members like: HasExtention, Extention etc to query the data. That way you
won't have to worry yourself with URI parsing.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

regex help 5
regex pattern 2
Verbatim String or Regex Pattern from Input 4
need help on regex 4
Regex in C# 4
Insert character using Regex 4
regex help 1
need some finer tuning on the regular expression 9

Top