>Cartoon swearing ahoy.

 

Maybe not ... well done! I've had your expression verified by myself, NASA
and the Vatican College of Cardinals.

 

It's not nearly as complicated as I expected, I tried a pattern-of-patterns
as the logical way to do it, but I kept getting only one match. But wait ...
I see that you've used Matches (not Match) for each key+val, which I
probably didn't try. I was looking for a match on a repeating pattern,
whereas you look for multiple matches of a single pattern. D'oh! I also
haven't used that <NAME> technique as I habitually use the offsets, but
yours is better for this sort of thing.

 

Greg

 

var input = "%KEY1, value1 %KEY2,value2   %KEY3, %NOTE,This is a note %NAME,
Fred Knuckle";

var regex = @"\s*%(?<KEY>[^,]+),\s*(?<VALUE>[^%]*)";

var matches = Regex.Matches(input, regex);

Reply via email to