0

I have this code:

var regex1 = /https:\/\/firebasestorage\.googleapis\.com\/v0\/b\/uczsieapp\.appspot\.com\/o\/images%2F/;
var regex2 = /\?alt=media&token=dca85b39-e6e7-43ac-bfef-d098cb33c7d3/;
worksLinks = worksLinks.map(link => {
    link.replace(regex1, '');
    link.replace(regex2, '');
    console.log(link);
    return link;
});

My string looks like this:

https://firebasestorage.googleapis.com/v0/b/uczsieapp.appspot.com/o/images%2F50531a3b-826c-4f8d-a597-a419eab083f0?alt=media&token=dca85b39-e6e7-43ac-bfef-d098cb33c7d3

Essentially I want to take the file name out of the link. In this case the file name is here:

https://firebasestorage.googleapis.com/v0/b/uczsieapp.appspot.com/o/images%2F >50531a3b-826c-4f8d-a597-a419eab083f0< ?alt=media&token=dca85b39-e6e7-43ac-bfef-d098cb33c7d3

I tried using regex101, and it works there. But when I try to replace it in JS nothing happens.

I created 2 different regexes, cause I didn't know how to use the wildcard properly here, but that's not what the question is about.

Here's the link to regex 101: https://regex101.com/r/aotx1E/1

I used this documentation: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace

Alex Ironside
  • 4,658
  • 11
  • 59
  • 119

0 Answers0