Using regular expressions in C#, VS 2010. Here’s the code.
static string capturePattern = @"\|([!-|]{2})([!-|]{2})([!-|]{2})?([!-|]{2})?([!-|]{2})?([!-|]{2})?([!-|]{2})?\|";
Regex rgx = new Regex(capturePattern);
string TS="!3829.87N/12033.82Wv169/000|!('d%*|"
MatchCollection matches = rgx.Matches(TS);
matches.Count ends-up being 1 and matches[0] is “|!(‘d%*|”.
I was expecting matches.Count to be 3, and parsed strings to be:
matches[0] = "!("
matches[1] = "'d"
matches[2] = "%*"
What did I do wrong?
Chuck
Your regex captures everything between the bars
|into a single match. If you want the parts in parenthesis, those are inmatch[0].Groups.Group[0]is the whole capture group. Groups 1, 2, and optionally, 3 and more are going to be the character pairs in parenthesis.In your case, matches.Count will be 1, matches[0].Groups.Count will be 4, with :