我收到如下字符串响应:
{'url': <ImageFieldFile: photologue/photos/spiderman.png>}{'url': <ImageFieldFile: photologue/photos/superman_PucGOkm.jpg>}
我只需要 photologue/photos/spiderman.png 和 photologue/photos/superman_PucGOkm.jpg 来自这可以构造具体的网址,如下所示:
http://127.0.0.1:8000/media/photologue/photos/spiderman.png
我怎样才能在 typescript 中做到这一点? 我的 angular2 组件函数:
fetchGallery(id: number){
this.showImages=true;
this.galleryService.fetchGallery(id)
.then(
response => {
this.gallery = response;
console.log(typeof(this.gallery._body))
});
}
最佳答案
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)
在数组中,您已提取路径。
关于javascript - typescript 提取字符串的一部分以进一步处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40951147/