我需要什么类型的正则表达式来从markdown中提取图像url

What type of regexp would I need to extract image url from markdown?

本文关键字:markdown 提取 url 图像 正则表达式 什么 类型      更新时间:2023-09-26

给定以下

Some post content here
![Habits Are Hard to Build and Break](https://i.stack.imgur.com/tToTx.jpg)
Yad ayaday dyaya 
 * Hi
 * There

如何提取markdown中的第一个图像?例如,我基本上想解析它,然后将第一个图像保存到像extractedImage这样的变量中。"https://i.stack.imgur.com/tToTx.jpg"

extractImageFromMarkdown(text) {
  // somehow parse text to grab first image_url
  return extractedImageUrl;
}
text.match(/!'[.*?']'((.*?)')/)[1]

这假设您不能有任何转义括号,比如![']],这可能是一个安全的假设。这也将根据请求仅获得第一个图像。