2016-12-03 13 views
0

我得到一個串響應如下:打字稿提取部分來處理進一步

{'url': <ImageFieldFile: photologue/photos/spiderman.png>}{'url': <ImageFieldFile: photologue/photos/superman_PucGOkm.jpg>} 

我只需要photologue /照片/ spiderman.pngphotologue /照片/ superman_PucGOkm。 JPG從這個來構建具體的網址,像以下:

http://127.0.0.1:8000/media/photologue/photos/spiderman.png

我該如何在打字稿中做到這一點? 我angular2部件功能:

fetchGallery(id: number){ 

    this.showImages=true; 
    this.galleryService.fetchGallery(id) 
    .then( 
     response => { 
      this.gallery = response; 
      console.log(typeof(this.gallery._body)) 

     }); 
} 

回答

1
let url = "{'url': <ImageFieldFile: photologue/photos/spiderman.png>}{'url': <ImageFieldFile: photologue/photos/superman_PucGOkm.jpg>}"; 
let array = url.match(/[A-Za-z0-9\/_]+\.[a-zA-Z]+/g) 

在陣列已提取的路徑。

+0

是的這看起來是正確的,但也可能有.jp​​g圖像,你可以在返回的字符串中看到。所以我需要以某種方式同時提取兩者。 – Nitish

+0

我已更新答案,現在任何文件擴展名將被提取 – mitch

+0

它仍然以某種方式給我只有一個字符串而不是兩個 – Nitish