URL中的正则表达式,用于匹配ID

用户254197

我需要像这样的正则表达式(实际上是“ =”和“&”之间的ID(数字),例如“ = 376629&”):

http://gatherer.wizards.com/Pages/Card/Details.aspx?multiverseid=376629&part=Borrowing+100%2c000+Arrows

我发现的是:

      [^0-9$,]

但这不符合以下条件:

http://gatherer.wizards.com/Pages/Card/Details.aspx?multiverseid=376629&part=Borrowing+100%2c000+Arrows

只有这个:

http://gatherer.wizards.com/Pages/Card/Details.aspx?multiverseid=85808&part=Boseiju%2c+Who+Shelters+All

这场比赛将是我想要的“ 85808”。

可能是您可以帮助我,谢谢。

Pushpraj

正则表达式

id=(\d+)

第一次捕获包含结果

测试字符串

http://gatherer.wizards.com/Pages/Card/Details.aspx?multiverseid=376629&part=Borrowing+100%2c000+Arrows
http://gatherer.wizards.com/Pages/Card/Details.aspx?multiverseid=85808&part=Boseiju%2c+Who+Shelters+All

结果

  • 比赛1
    1. 376629
  • 比赛2
    1. 85808

演示版

在线演示

C#示例

    string hrefValue = "http://gatherer.wizards.com/Pages/Card/Details.aspx?multiverseid=85808&part=Boseiju%2c+Who+Shelters+All";
    string id = Regex.Match(hrefValue, @"id=(\d+)").Groups[1].Value;

在线C#演示

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章