Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Regular Expression Problem
Message
De
20/06/2012 13:49:23
 
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01546399
Message ID:
01546456
Vues:
51
J'aime (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;
}
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform