Re: regex help

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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

.



Relevant Pages

  • Re: need help on regex
    ... i'm trying to see if a string ends with teh below ... can someone help me out with teh correct pattern ... You can solve this issue with regular expresions with the following expression: ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: regex help
    ... i'm trying to see if a string ends with teh below ... can someone help me out with teh correct pattern ... Your regular expression is correct. ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: pumping lemma (third try)
    ... >> you a string not in L. ... >> contradiction and the proof that L isn't regular breaks down. ... > and answering my wannabe trials and questions. ... > there are no adjacent equal substrings. ...
    (comp.theory)
  • Re: [PATCH] nconfig: add search support
    ... and replace by a regular string search. ... From nconfig help: ... free terminal real-estate to display the match string was at the top ...
    (Linux-Kernel)
  • Re: pumping lemma (third try)
    ... some string x followed by its reverse.} ... > I will assume that L is regular and therefore the pumping lemma ... > Now I will divide the PL string w into the PL substrings x, ...
    (comp.theory)