2014-10-17 28 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