用下面的正则表达式,它不匹配-lp [数字]发送到我的功能正则表达式匹配问题
public static Regex lPageID = new Regex(@"\-lp\d+\.", RegexOptions.Compiled | RegexOptions.IgnoreCase);
public static int GetPageIDFromPath(string path)
{
return GetIDFromPath(lPageID, path);
}
例如路径:
/域/有些着陆页-元-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;
}
我需要抓取-lp后面的数字。这似乎是它不喜欢多余的字符或没有像宝洁这样的,因为如果我改变了正则表达式的单个字母后-l正常工作 - 如:
public static Regex lPageID = new Regex(@"\-l\d+\.", RegexOptions.Compiled | RegexOptions.IgnoreCase);
与示例串:/domain/Some-Landing-Page-Meta-Title-l1.l
它适用于我 - 你确定没有其他影响结果的东西吗?有更多的代码可以发布吗? – 2009-07-16 20:16:41
您需要向我们展示更多代码。这在我的快速测试中起作用。 – 2009-07-16 20:18:32