Search code examples
arraysregexgoogle-sheetsindexinggoogle-sheets-formula

REGEXEXTRACT before a group of characters in google sheets


I have this google sheets table with input in column A I need this output on the right.

Input Desired Output
"https://www.example.com/sub.php?id=54128754" https://www.example.com/sub.php?id=54128754
"https://www.example.com/sub-new-45184832/" https://www.example.com/sub-new-45184832
"https://www.example.com/sub-new2-495174885/" https://www.example.com/sub-new2-495174885

But when trying this formula:

=ArrayFormula(REGEXEXTRACT(A2:A4, "(.+)[\""|\/]"))

This is what I came up with.

Input Output
"https://www.example.com/sub.php?id=54128754" "https://www.example.com/sub.php?id=54128754
"https://www.example.com/sub-new-45184832/" "https://www.example.com/sub-new-45184832/
"https://www.example.com/sub-new2-495174885/" "https://www.example.com/sub-new2-495174885/

How to extract everything between "(*)", or "(*)/".
In other word if ended with " or /"

Thanks in advance.


Solution

  • try:

    =INDEX(REGEXEXTRACT(A1:A3, """(.+?)(?:\/)?"""))
    

    enter image description here