2016-01-21 24 views
0

我試圖提取URL,但每次我運行我的代碼。它沒有工作。錯過了什麼?任何幫助都會很棒。gsub錯誤提取URL與R,我錯過了什麼

X $ URL < - ( 「(*)(http://www.bloomin.com)(JPG)()。」
「// 2 // 3」 中,x $ Product.Description。)GSUB

[1] // 2 // 3

這是我回來。我想從vector下面得到http://www.blooming.com/image/xxxxxxxx.jpg

<div>Colorful Floor chair Series</div><div><br /></div><div>Soft 
Suede</div><div><br /></div><div>Cute bubble design</div><div><br 
/></div><div><p align="center"><p align="center"><img 
src="http://gdetail.image-gemkt.com/186/716088198/2010/2/e3b117e2-a7bd-4d.GIF" 
/></div><div><p align="center"><p align="center"><img 
src="http://www.blooming.com/image/xxxxxxxx.jpg" /></div> 
+4

嗯哦。正則表達式與HTML? http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454 – JackeJR

+0

並非如此:這是關於在HTML中匹配URL,而不是匹配HTML標籤(鏈接的響應是適當的)。 – legoscia

回答

3
  1. 反向引用必須用反斜槓refered沒有斜槓。

  2. 使用.*?非貪婪)來匹配其存在其間.com的所有字符和文件擴展名.jpg

    x$URL <- gsub("(?s).*\\b(http://www\\.blooming\\.com\\b.*?\\.jpg\\b).*", 
               "\\1", x$Product.Description.) 
    

DEMO

+0

你救了我!非常感謝 – HoKyun