Avec l'expression rationnelle suivante, il ne correspond pas à -lp [nombre]Regex numéro match
public static Regex lPageID = new Regex(@"\-lp\d+\.", RegexOptions.Compiled | RegexOptions.IgnoreCase);
public static int GetPageIDFromPath(string path)
{
return GetIDFromPath(lPageID, path);
}
exemple chemin qui est envoyé à ma fonction:
/domain/Some-Landing-page-Meta -Title-lp1.lp
private static int GetIDFromPath(Regex regex, string path)
{
Match match = regex.Match(path);
if (match.Success)
{
string value = match.Value;
value = value.Substring(2, value.Length - 3);
int id;
if (Int32.TryParse(value, out id))
return id;
}
return 0;
}
Je dois saisir le nombre après -lp. Il semble être qu'il n'aime pas le caractère supplémentaire ou n'aime pas parce que p -l fonctionne très bien si je change le regex à une seule lettre après - tels que:
public static Regex lPageID = new Regex(@"\-l\d+\.", RegexOptions.Compiled | RegexOptions.IgnoreCase);
par exemple chaîne de : /domain/Some-Landing-Page-Meta-Title-l1.l
Cela fonctionne pour moi - êtes-vous sûr qu'il n'y a pas d'autre chose qui affecte le résultat? Y a-t-il plus de code que vous pouvez poster? –
Vous devrez nous montrer plus de code. Cela fonctionne dans mes tests rapides. –