regex pattern

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
 
L

Luc E. Mistiaen

Well, your construct [\w|\W] is a bit awkward: anything between the square
bracket will cause a match; because you have \w (word characters) and \W
(non-word characters), you match everything (the | is not needed between
square brackets: it will be matched...)

try something like \\\w+\.xlsx?
 
K

Kevin Spencer

\\[^?\[\]\/\\=+\<\>:;",*\r\n]+\.xlsx?

The regular expression above does the following for a match:

1. Begins with a backslash
2. Followed by any character not in the list \?[]/\=+<>:;",*\r\n (illegal
Windows file name characters), one or more
3. Followed by ".xls"
4. Followed by 'x' (Zero or 1 time)

--
HTH,

Kevin Spencer
Microsoft MVP

DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net
 

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
need help on regex 1
Verbatim String or Regex Pattern from Input 4
Simple regex question! 2
regex: NOT operation 1
need help on regex 2
regex pattern 4
Wildcard String Search 6

Top