我需要一個正則表達式( 「=」 和 「&」,例如 「= 376629 &」 之間實際的ID(數字))是這樣的:正則表達式中的URL相匹配的ID
我發現是這樣的:
[^0-9$,]
但這將不會匹配這樣的:
只有這個:
本場比賽將是我想要的 「85808」。
可能是你可以幫助我,謝謝。
我需要一個正則表達式( 「=」 和 「&」,例如 「= 376629 &」 之間實際的ID(數字))是這樣的:正則表達式中的URL相匹配的ID
我發現是這樣的:
[^0-9$,]
但這將不會匹配這樣的:
只有這個:
本場比賽將是我想要的 「85808」。
可能是你可以幫助我,謝謝。
正則表達式
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
結果
376629
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;
如果你想
ty,它的工作:) – user254197 2014-09-20 05:26:58
對不起,我仍然獲得了出現FormatException,當excecute您正則表達式(Regex.Replace(hrefValue,@ 「?(?<==)[0-9] +(?=&)」,string.Empty))... – user254197 2014-09-20 04:53:33
我猜不支持後面的不支持 – pushpraj 2014-09-20 04:54:13
@ user254197你爲什麼要用replace方法? – 2014-09-20 04:56:03
'=','&'也再使用,'= \ d +' – 2014-09-20 04:57:59