Published: 17 Jan 2020 › Updated: 17 Jan 2020
js使用正则提取Markdown文本中的图片 / 网络研习社#58
需求:在一段Markdown文本中提取出图片。比如:Steem中的图片都是直接存在'post.body'中的,如果想要单独显示,则需要使用正则提取出来。
let reg = /\!\[.*?\)/
//提取第一张图片格式:![]()
//以'↵↵在上一篇《零代
码用IPFS做文件服务器》中启动了IPFS网络,至少
看起来简单。[星空笔记](https://starnote.github.io)就不错!"
let a = str.match(reg)
if(a ===null){ //如查没有图片,直接返回
return
}
console.log(1234, a[0])
//""
let reg2= /https:\/\/.*\w/ //从md中提取链接
let res = a[0].match(reg2)
console.log(23456, res[0])
// "https://cdn.steemitimages.com/DQ4dtGLyG3AZr9Nzmm/ipfs3.jpg"
Leave js使用正则提取Markdown文本中的图片 / 网络研习社#58 to:
Read more #cn posts
Best Posts From lemooljiang
We have not curated any of lemooljiang's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.