You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Googlesheet正则表达式:仅从多个图片URL中捕获首个URL

Grab the First Image URL in Google Sheets with Regex

If you need to pull the very first image URL from a chunk of HTML (like your example with multiple <a> tags and image attributes), here's a straightforward solution using Google Sheets' REGEXEXTRACT function:

Step 1: The Regex Formula

Use this formula in a blank cell, replacing A1 with the cell holding your HTML content:

=REGEXEXTRACT(A1, "https?://[^"]+")

How It Works

Let’s break down the regex pattern to make sense of it:

  • https?://: Matches both http:// and https:// URLs (the ? makes the s optional, covering both secure and non-secure links)
  • [^"]+: Matches any character that isn’t a double quote — since your image URLs are wrapped in quotes inside HTML attributes, this ensures we capture the full URL up to the closing quote of the first attribute.

Since REGEXEXTRACT returns the first match it finds by default, this will grab exactly the first image URL from your content.

Optional: Target Multiple Image Formats

If your content includes other image types (like .png, .gif, or .jpeg), tweak the regex to only pull valid image URLs:

=REGEXEXTRACT(A1, "https?://[^"]+\.(jpg|jpeg|png|gif)")

Test with Your Example

For your sample input:

<a data-zoom-image="https://www.example.com/media/catalog/product/cache/1/image/5f444a2891627135a18d90f22b51fc0/d/m/dm104-2.jpg" , data-image="https://www.example.com/media/catalog/product/cache/1/image/500x500/35f444a289162715a18d90f22b51fc0/d/m/dm104-2.jpg"> <a data-zoom-image="https://www.example.com/media/catalog/product/cache/1/image/35f444a28916...

The formula will return:
https://www.example.com/media/catalog/product/cache/1/image/5f444a2891627135a18d90f22b51fc0/d/m/dm104-2.jpg

内容的提问来源于stack exchange,提问作者disha

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 08:40:14