Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Regular Expression Problem
Message
 
À
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:
01546461
Vues:
35
Yup, I'm stupid.

Thanks


>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;
>}
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform