Osm
Osm

Reputation: 2881

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.

Upvotes: 0

Views: 52

Answers (2)

TheMaster
TheMaster

Reputation: 50382

The regex is simple:

  • start with ": ^"
  • capture () anything but ": [^"]
  • ends with ": "$
  • Since, " is a argument delimiter, we need to escape " by doubling it: "".

Regex:

"^""([^""]+)""$"

If you want to remove the last / as well, make the capture group non-greedy(+?) and add / before the " as optional:

"^""([^""]+?)/?""$" 

Upvotes: 1

player0
player0

Reputation: 1

try:

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

enter image description here

Upvotes: 1

Related Questions