0

I have a list of URLs like

https://www.example.com/inn/abc_name_of_the_product_w/o_additional_information.132.jpeg

I don´t know how they include a slash in the file name... and it could be more than one time in the same file name!

I need to perform a REGEXREPLACE to replace any slash (/) in the filename by a dash (-), but not those in the URL... so it should keep up to the 4th slash in the string.

So given example should look like:

https://www.example.com/inn/abc_name_of_the_product_w-o_additional_information.132.jpeg

And a basic REGEXREPLACE(A2,"/","-") replaces ALL the slashes in the string, that is not what I want.

I've tried many alternatives, but my knowledge has a very low limit on the regex syntax, that I cannot fully understand, no matter how many references and tutorials I read about it. =(

Any help would be appreciated! =)

RavinderSingh13
  • 130,504
  • 14
  • 57
  • 93
Speedbit
  • 59
  • 9
  • In sample URL `https://www.example.com/inn/abc_name_of_the_product_w/o_additional_information.132.jpeg` is url always fixed till `https://www.example.com/inn` and later on values can be dynamic? Please confirm once. – RavinderSingh13 Aug 09 '22 at 05:52
  • Hi @RavinderSingh13 sorry for my late reply... I didn't see your comment before! By the given example, `https://www.example.com/inn/` is **fixed**... all beyond this, is **dynamic** and could be different, from one item to another. Even, it can include more than one slash in the file name, that I would need to replace by a dash, too! - Thanks for your attention to my question! =) – Speedbit Aug 09 '22 at 14:51

1 Answers1

2

Use REGEXEXTRACT() then SUBSTITUTE()`

=REGEXEXTRACT(A1, "^(?:[^/]*/){4}") & SUBSTITUTE(REGEXEXTRACT(A1, "^(?:[^/]*/){4}(.+)"),"/","_")

enter image description here

Harun24hr
  • 30,391
  • 4
  • 21
  • 36
  • Thank you Harun24hr. I will try it! Just to let me understand: there is no way to do it by pure REGEXREPLACE?? Or this is just a workaround? I'm interested in the REGEX syntax, sadly I don´t understand. – Speedbit Aug 09 '22 at 07:04
  • 1
    @Speedbit I think there must way to use `REGEXREPLACE`. I will explore little more. – Harun24hr Aug 09 '22 at 07:19
  • Thank you very much! Your solution using REGEXREPLACE + SUBSTITUTE works perfectly. Anyway, I would love to know the way to do it by pure REGEXREPLACE (if it's possible!)... just for the challege which I couldn't get jejeje I'll be glad to hear about you. THX =) – Speedbit Aug 09 '22 at 13:34