Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Regular Expression Problem
Message
From
20/06/2012 13:49:23
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01546399
Message ID:
01546456
Views:
50
Likes (1)
You're running the Regex against the word instead of the line. Try this:
private static string getKeyValue(ref string Line, string WordToFind)
{
	var retVal = string.Empty;

	if (Line.Contains(WordToFind))
	{
		Regex r = new Regex(@"(?:(?'Key'\S+): (?'Value'(?:.(?!\s+\S+:))*))",
						RegexOptions.RightToLeft |
						RegexOptions.CultureInvariant |                                
						RegexOptions.Compiled);

		var matches = r.Matches(Line);

		var wordMatch = matches.OfType<Match>().Where(match => match.Groups["Key"].Value == WordToFind);
		if (wordMatch.Any())
		{
			retVal = wordMatch.First().Groups["Value"].Value;
		}
	}

	return retVal;
}
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform