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,
I'm having hard times using Regular Expressions.

Here is what I'm doing:

string s = "111111111[[Include (test)]]2222222[[include (header)]]33333;

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 I'm getting is:
"[[Include (test)]]2222222[[include (header)]]" - just one match
I would prefer something like:
"[[Include (test)]]"
"[[include (header)]]" - two matches.

Could somebody tell me what I need to change in my pattern? And how can
I get position of each match withing the string?
Any help appreciated.

Regards,
Dmitry.
Dmirtry Mukhin

2004-06-24, 12:57 am

Dmirtry Mukhin wrote:

Sorry for the duplicated post. I've figured it out
The right pattern is "\[\[Include \((.*?)\)\]\]"

Regards,
Dmitry.
Sponsored Links







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

Copyright 2008 codecomments.com