I would like to match these lines:
ParameterINeed: 758
ParameterCount: 8695
ParameterText: 56
And I would receive a parameter name and parameter value. Could you please tell me how to write Regex.Matches patter for this and how to process this data into Dictionary?
I use this code:
string Text = "ParameterINeed: 758\r\nParameterCount: 8695\r\nParameterText: 56";
string Pattern = "^(\\w+):\\s+(\\d+)$";
MatchCollection ma = Regex.Matches(Text, Pattern, RegexOptions.Singleline);
And get ma.Count = 0
The
RegexOptions.SingleLineonly affects how the period token works, not how the ^ and $ tokens work. You need to useRegexOptions.MultiLinefor that.The multiline mode doesn’t understand the \r\n line breaks, it only considers the \n character as line break. You have to consume the \r character to get to the line break.
Now
ma.Countis 3.This is how you put the matches in a dictionary: