2014-10-17 23 views
1

我需要拔出C5044SGXAU了以下網址:如何從url中取出一個子串?

<div class="zg_itemImageImmersion"><a href="http://www.website.com/Doggy-PIC-14-Pitbull-Induction-1500-Matt/dp/C5044SGXAU/ref=zg_bs_3741261_1"><img src="http://dog.images-website.com/images/I/41dXgzYztML._SL160_SL150_.jpg" alt="Doggy PIC-14 Pitbull Induction Cookt..." title="Doggy PIC-14 Pitbull Induction Cookt..." onload="if (typeof uet == 'function') { uet('af'); }"></a></div> 

我試圖得到這個結果:

C5044SGXAU 

如何做到這一點?

回答

1

使用以下的正則表達式

http:\/\/[^\/]+\/[^\/]+\/[^\/]+\/([^\/]+)\/[^\/]+

Demo

+0

嘿Venky,它似乎並不在我的計劃時工作。它顯示以下... http://www.website.com/Doggy-PIC-14-Pitbull-Induction-1500-Matt/dp/C5044SGXAU/ref=zg_bs_3741261_1 「> user3266989 2014-10-17 07:38:19

+0

Can you post the part of your program where you are using this regex? – Venky 2014-10-17 08:38:52

+0

Not sure if this would help but here it is... set(#dddf, $find regular expression(#ddd, "http:\\/\\/[^\\/]+\\/[^\\/]+\\/[^\\/]+\\/([^\\/]+)\\/[^\\/]+"), "Global") – user3266989 2014-10-17 08:52:53