A
Amy L.
I am having a hard time figuring out why this regular expression does not
have multiple captures for the group. When checking the regular expression
in a testing tool like "Expresso" it seems to work fine.
Input (All on one line - watch for wordwrap):
Student Results [weight=103]: SMITH=PASS JONES=WARN WRIGHT=WARN JOHNSON=WARN
Regular Expression:
(?<studentname>([\w-!\[\].,;:?/!@#$%^&*()<>{}|\~`'"=+-]+))=\w+(?:\s+|$)
Expected Output: A Group with multiple captures of: "SMITH", "JONES",
"WRIGHT".
Code I was using:
Regex myRegexTest = new Regex(
@"(?<studentname>([\w-!\[\].,;:?/!@#$%^&*()<>{}|\~`'""=+-]+))=\w+(?:\s+|$)",
RegexOptions.IgnoreCase | RegexOptions.Compiled ) ;
m = myRegexTest.Match( sText.ToString() ) ;
Console.WriteLine( "Groups Count: " + m.Groups.Count ) ;
Console.WriteLine( "Groups Capture 0: " + m.Groups[0].Captures.Count ) ;
Console.WriteLine( "Groups Capture 1: " + m.Groups[1].Captures.Count ) ;
Console.WriteLine( "Groups Capture 2: " + m.Groups[2].Captures.Count ) ;
When I look at the output I get 3 groups each with one capture. When I look
at whats captured I always end up with just "SMITH" and never the other two
names.
Any help would be greatly appreciated.
Amy.
have multiple captures for the group. When checking the regular expression
in a testing tool like "Expresso" it seems to work fine.
Input (All on one line - watch for wordwrap):
Student Results [weight=103]: SMITH=PASS JONES=WARN WRIGHT=WARN JOHNSON=WARN
Regular Expression:
(?<studentname>([\w-!\[\].,;:?/!@#$%^&*()<>{}|\~`'"=+-]+))=\w+(?:\s+|$)
Expected Output: A Group with multiple captures of: "SMITH", "JONES",
"WRIGHT".
Code I was using:
Regex myRegexTest = new Regex(
@"(?<studentname>([\w-!\[\].,;:?/!@#$%^&*()<>{}|\~`'""=+-]+))=\w+(?:\s+|$)",
RegexOptions.IgnoreCase | RegexOptions.Compiled ) ;
m = myRegexTest.Match( sText.ToString() ) ;
Console.WriteLine( "Groups Count: " + m.Groups.Count ) ;
Console.WriteLine( "Groups Capture 0: " + m.Groups[0].Captures.Count ) ;
Console.WriteLine( "Groups Capture 1: " + m.Groups[1].Captures.Count ) ;
Console.WriteLine( "Groups Capture 2: " + m.Groups[2].Captures.Count ) ;
When I look at the output I get 3 groups each with one capture. When I look
at whats captured I always end up with just "SMITH" and never the other two
names.
Any help would be greatly appreciated.
Amy.