Regular expression required

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Feb 2009
Posts: 15
Reputation: ppraj is an unknown quantity at this point 
Solved Threads: 0
ppraj ppraj is offline Offline
Newbie Poster

Regular expression required

 
0
  #1
Mar 4th, 2009
Hi,

I need to match the following full string using Regular Expression :
  1. load "\fiostvmercury\Src\fiostv\server\Admin Console\Build"

Let me know
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: Regular expression required

 
0
  #2
Mar 4th, 2009
Um, you could put exactly that in (with double \\ marks obviously) why what problem you having with it?
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 15
Reputation: ppraj is an unknown quantity at this point 
Solved Threads: 0
ppraj ppraj is offline Offline
Newbie Poster

Re: Regular expression required

 
0
  #3
Mar 4th, 2009
Hi

I used pattern as the below. The complete text is a multiline string and the serach pattern can occur in any of these lines. So wherever the string starts with load , I would require to print the whole line of it.
  1.  
  2. Regex reg = new Regex(@"^load", RegexOptions.Multiline);
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: Regular expression required

 
0
  #4
Mar 5th, 2009
OK, so what happened when you did it..
You know how it goes show your code, show what happened, show what you found but werent expecting..
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 15
Reputation: ppraj is an unknown quantity at this point 
Solved Threads: 0
ppraj ppraj is offline Offline
Newbie Poster

Re: Regular expression required

 
0
  #5
Mar 5th, 2009
He,

Have a text file with the following contents :

  1. Hi just a test text
  2. load \fiostvmercury\Src\fiostv\server\Build
  3. load \fiostvmercury\Src\fiostv\server\WFAdminConsole\Build
  4. load "\fiostvmercury\Src\fiostv\server\Admin Console\Build"

Now, you can use the following code :

  1. StreamReader sr = new StreamReader("D:\\ViewStorage\\cc.txt");
  2.  
  3. string regmatch = @"^load";
  4. string output = sr.ReadToEnd();
  5. MatchCollection mc;
  6. mc = Regex.Matches(output, regmatch,RegexOptions.Multiline);
  7. if (mc.Count > 0)
  8. {
  9. for (int i = 0; i < mc.Count; i++)
  10. {
  11. Console.WriteLine(mc[i].Value);
  12. }
  13. }
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: Regular expression required

 
0
  #6
Mar 5th, 2009
So, you didnt bother with the other half of my post then.
You dont seem to be debugging your code, as you dont seem to be able to show me what you found.. only that "heres some code, you look for yourself."
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 15
Reputation: ppraj is an unknown quantity at this point 
Solved Threads: 0
ppraj ppraj is offline Offline
Newbie Poster

Re: Regular expression required

 
0
  #7
Mar 6th, 2009
Lizr,

Thanks for your co-operation so far. The above code which was posted printed "load" thrice , but my expectation was to print the whole line starting with "load".
However, I have done away with regular expressions and is reading the text line by line using StreamReader and wherever it starts with load I get it .
May be it is not a bad idea, if I can get the regular expression to work .
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: Regular expression required

 
0
  #8
Mar 6th, 2009
regexpressions arent hard, but rather than just stumble about go to http://RegExpStudio.com and play with the studio product, it will help you undertand more.
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC