Search code examples
regexurlgoogle-sheets-query

Googlesheet Regex : only capture first URL from multiple image URL


Example 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/70x70/35f444a2891627135a18d90f2b51fc0/d/m/dm104-2.jpg" a data-zoom-image="https://www.example.com/media/catalog/product/cache/1/image/35f444a2891627135a18d9022b1fc0/m/i/mirror_disclaimer_web_16.jpg" )

I want to capture only the first url after that part (< a data-zoom-image=")

(https://www.example.com/media/catalog/product/cache/1/image/5f444a2891627135a18d90f22b51fc0/d/m/dm104-2.jpg)

How can I do that in googlesheet using regularexpression.

Thanks in advance


Solution

  • You can use the REGEXEXTRACT method like this

    =REGEXEXTRACT(A24, "data-zoom-image=""([^\""]*)")
    

    Explanantion -

    data-zoom-image="" -- match for exact text data-zoom-image=" (using "" to represent ") ([^\""]*) -- first capturing group, this is the result that would be displayed
    [^\""] -- any character that is not " (again using "")
    * -- match zero or more times