2016-04-04 50 views
-3

我想從具有使用javascript的img srcset的html獲取圖像url。我特別有興趣獲得第二或第三張照片。 srcset的HTML內使用JavaScript正則表達式從html srcset獲取圖像url

實施例:

<img srcset=\"http:example.jpg 140w,http:example.jpg 160w,http:example.jpg 320w,http:example.jpg 480w,http:example.jpg 720w,http:example.jpg 1280w,http:example.jpg 1500w\" src=\"http:example.jpg\" alt=\"example\"> 

我只能用純的JavaScript。

任何幫助將非常感謝,因爲我已經花了數小時試圖獲得這項工作,迄今爲止我獲得的唯一成功是將所有這些鏈接從html中取出。

+0

[不要用正則表達式解析HTML](http://stackoverflow.com/a/1732454/418066) – Biffen

+1

什麼問題?你嘗試過什麼,它不起作用? – Biffen

+0

準確的預期輸出是什麼? – Shafizadeh

回答

0

嘗試:http:[^ ]+

你將不得不澄清,如果這不符合您的需求。

說明
  • http:發現字面

  • [^ ]+找到多個非空格字符。