From: Jeff Johnson on 23 Feb 2010 16:06 "Matthijs de Z" <matthijsdezwart(a)gmail.com> wrote in message news:34b09643-66fb-4602-b166-888c0779dd35(a)n5g2000vbq.googlegroups.com... >> > I tried to add Path.DirectorySeparatorChar.ToString() to the front of >> > the regular expression string, I get it twice. > >> > string myDefaultName = @Path.DirectorySeparatorChar + "defaultName"; >> > string regExpression = "("+myDefaultName+@"[0-9]{8}\.[zZ][iI][pP])"; > >> > Gives me "(\\defaultName[0-9]{8}\\.[zZ][iI][pP])" as a regular >> > expression, while DirectorySeparatorChar is actually just one \ >> > (although I can see it twice again in the result set) > >> When you say "I get it twice," what are you using to make this >> determination? Are you simply looking at the tooltip display in the >> debugger? > when I hover over the variable that contains the string > (myDefaultName) I see \\ but when I add the string to a richTextBox I > just see one. So I suppose it's just one \. So then you're seeing exactly what I described. > But still....it doesn't work... See my other reply.
From: Jeff Johnson on 23 Feb 2010 16:06 "Matthijs de Z" <matthijsdezwart(a)gmail.com> wrote in message news:d97baa89-7a49-43ff-be51-d2b5c172319a(a)k11g2000vbe.googlegroups.com... >> If you are trying to match on the filename only, it seems to me you'd be >> better off preprocessing the path before you hand it to the regex. Just >> use the Path class, with the GetFileName() method, to obtain only the >> filename portion of the path, then match that against the regex. > if I do that, i think I will still have a problem with for > instance:'copy defaulName20100223.zip' > How can I make sure I only get the names like defaulName20100223.zip? > regards, Put ^ at the beginning of the regex so that it only matches if the string starts with the default name.
From: Matthijs de Z on 23 Feb 2010 16:28 On 23 feb, 22:06, "Jeff Johnson" <i....(a)enough.spam> wrote: > "Matthijs de Z" <matthijsdezw...(a)gmail.com> wrote in messagenews:d97baa89-7a49-43ff-be51-d2b5c172319a(a)k11g2000vbe.googlegroups.com... > > >> If you are trying to match on the filename only, it seems to me you'd be > >> better off preprocessing the path before you hand it to the regex. Just > >> use the Path class, with the GetFileName() method, to obtain only the > >> filename portion of the path, then match that against the regex. > > if I do that, i think I will still have a problem with for > > instance:'copy defaulName20100223.zip' > > How can I make sure I only get the names like defaulName20100223.zip? > > regards, > > Put ^ at the beginning of the regex so that it only matches if the string > starts with the default name. when I use string regExpression = @"^([0-9]{8}\.[zZ][iI][pP])"; It doesn't work, unless I trimdown the filename, cutting of all directory info. But I need need that actually.. Regards, Matthijs
From: Jeff Johnson on 23 Feb 2010 16:48 "Matthijs de Z" <matthijsdezwart(a)gmail.com> wrote in message news:49ba1cee-1446-4728-a13b-59d83e172a60(a)d27g2000vbl.googlegroups.com... >> >> If you are trying to match on the filename only, it seems to me you'd >> >> be >> >> better off preprocessing the path before you hand it to the regex. >> >> Just >> >> use the Path class, with the GetFileName() method, to obtain only the >> >> filename portion of the path, then match that against the regex. >> > if I do that, i think I will still have a problem with for >> > instance:'copy defaulName20100223.zip' >> > How can I make sure I only get the names like defaulName20100223.zip? >> > regards, >> >> Put ^ at the beginning of the regex so that it only matches if the string >> starts with the default name. > > when I use > string regExpression = @"^([0-9]{8}\.[zZ][iI][pP])"; > > It doesn't work, unless I trimdown the filename, cutting of all > directory info. But I need need that actually.. Well, I was building on what Pete said, and he suggested that you strip of the directory information. I didn't realize it was important to you. Does this work: string regExpression = @".*\\" + myDefaultName + "(\d{8}\.[zZ][iI][pP])$"; (I replaced [0-9] with \d, since they're the same. Also, you should just consider setting the case-insensistive option on the regex and test for "zip" instead of the way you're doing it now, unless case in the rest of the file name is important--but why would it be?)
From: Jeff Johnson on 23 Feb 2010 16:50 "Matthijs de Z" <matthijsdezwart(a)gmail.com> wrote in message news:49ba1cee-1446-4728-a13b-59d83e172a60(a)d27g2000vbl.googlegroups.com... [Reply sent too soon.] I also wanted to recommend that you go get a utility which will help you test regular expressions. I like Expresso, which is free. http://www.ultrapico.com.
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 Prev: Collection UserControls/Windows Controls Next: Help with insert using MySql |