For Programmers: Free Programming Magazines  


Home > Archive > C# > June 2004 > using Regular Expressions









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author using Regular Expressions
Dmirtry Mukhin

2004-06-24, 12:57 am

Hi guys, could somebody give me a hand. I'm having hard times using
Regular Expressions
Here is my code:

string s = "111111111111[[Include (text)]]22222222222[[Include
(header)]]"33333333333

Regex r = new Regex(@"(\[\[Include \(.*\)\]\])",
RegexOptions.IgnoreCase|RegexOptions.Compiled);

MatchCollection matches = r.Matches(s);
foreach (Match mt in matches)
{
Console.WriteLine(mt.Value);
}

The output is "[[Include (text)]]22222222222[[Include (header)]]" - only
one match.
But what I'm looking for is something like:
"[[Include (text)]]"
"[[Include (header)]]" - two matches

Could somebody tell me where I'm wrong? And how can I find position of
each occurrence withing the string?

Regards,
Dmitry.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com