2012-12-13 65 views
-7

如何從下面的數據中提取javascript中的網址?你能爲我寫代碼嗎?提取以下數據中的網址

[ 
Image{url:'/images/HH/Images/US/NYC/NYC-MEL-1.jpg', description='Exterior', 
      alt='null', sortOrder=1, externalUrl='null'}, 
Image{url='/images/HH/Images/US/NYC/NYC-MEL-9.jpg', description='Exterior', 
      alt='null', sortOrder=1, externalUrl='null'}, 
Image{url='/images/HH/Images/US/NYC/NYC-MEL-11.jpg', description='Lobby', 
      alt='null', sortOrder=4, externalUrl='null'}, 
Image{url='/images/HH/Images/US/NYC/NYC-MEL-5.jpg', description='Guest Room', 
      alt='null', sortOrder=34, externalUrl='null'}, 
Image{url='/images/HH/Images/US/NYC/NYC-MEL-6.jpg', description='Guest Room', 
      alt='null', sortOrder=34, externalUrl='null'}, 
Image{url='/images/HH/Images/US/NYC/NYC-MEL-7.jpg', description='Guest Room', 
      alt='null', sortOrder=34, externalUrl='null'}, 
Image{url='/images/HH/Images/US/NYC/NYC-MEL-8.jpg', description='Guest Room', 
      alt='null', sortOrder=34, externalUrl='null'}, 
Image{url='/images/HH/Images/US/NYC/NYC-MEL-10.jpg', description='Guest Room', 
      alt='null', sortOrder=34, externalUrl='null'}, 
Image{url='/images/HH/Images/US/NYC/NYC-MEL-3.jpg', description='Guest Room', 
      alt='null', sortOrder=34, externalUrl='null'}, 
Image{url='/images/HH/Images/US/NYC/NYC-MEL-2.jpg', description='Guest Room', 
      alt='null', sortOrder=34, externalUrl='null'}, 
Image{url='/images/HH/Images/US/NYC/NYC-MEL-4.jpg', description='Guest Room', 
      alt='null', sortOrder=34, externalUrl='null'} 
] 
+0

這不是堆棧溢出的工作原理 - 自己編寫代碼並在特定問題中復原 –

+0

沒有人會爲您做這項工作。做它你自己。如果您遇到問題,我們會盡力幫助您。 –

+0

你的文章除了分心之外什麼都不做 –

回答

2

好吧我只是給你一個簡單的想法,但沒有代碼:使用「拆分」的方法,即:

var myStr = "Hello, I'm here!"; 
var splitedString = myStr.split(", "); 

結果在splitedString是這樣["Hello","I'm here!"]數組。

祝你好運!

+0

是的,它不會是這樣普通的香草。這裏的操作必須一行一行地進行。然後他將不得不根據多個分隔符進行分割,例如:「:」,「=」,也只有在他找到一個名爲url的字符串之後才能分割。 –

+0

是的你是對的,但如果數據沒有格式化,你需要把它作爲一個簡單的字符串處理。 – fapm84