943,722 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 941
  • C# RSS
Mar 4th, 2009
0

Regular expression required

Expand Post »
Hi,

I need to match the following full string using Regular Expression :
C# Syntax (Toggle Plain Text)
  1. load "\fiostvmercury\Src\fiostv\server\Admin Console\Build"

Let me know
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ppraj is offline Offline
15 posts
since Feb 2009
Mar 4th, 2009
0

Re: Regular expression required

Um, you could put exactly that in (with double \\ marks obviously) why what problem you having with it?
Reputation Points: 196
Solved Threads: 190
Posting Virtuoso
LizR is offline Offline
1,735 posts
since Aug 2008
Mar 4th, 2009
0

Re: Regular expression required

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.
C# Syntax (Toggle Plain Text)
  1.  
  2. Regex reg = new Regex(@"^load", RegexOptions.Multiline);
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ppraj is offline Offline
15 posts
since Feb 2009
Mar 5th, 2009
0

Re: Regular expression required

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..
Reputation Points: 196
Solved Threads: 190
Posting Virtuoso
LizR is offline Offline
1,735 posts
since Aug 2008
Mar 5th, 2009
0

Re: Regular expression required

He,

Have a text file with the following contents :

C# Syntax (Toggle Plain Text)
  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 :

C# Syntax (Toggle Plain Text)
  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. }
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ppraj is offline Offline
15 posts
since Feb 2009
Mar 5th, 2009
0

Re: Regular expression required

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."
Reputation Points: 196
Solved Threads: 190
Posting Virtuoso
LizR is offline Offline
1,735 posts
since Aug 2008
Mar 6th, 2009
0

Re: Regular expression required

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 .
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ppraj is offline Offline
15 posts
since Feb 2009
Mar 6th, 2009
0

Re: Regular expression required

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.
Reputation Points: 196
Solved Threads: 190
Posting Virtuoso
LizR is offline Offline
1,735 posts
since Aug 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: how to signal WinForm control input out of range?
Next Thread in C# Forum Timeline: Want to execute a command on all files recursively





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC