I have these possible urls:
https://letterboxd.com/username/film/sometitle/
https://letterboxd.com/username59/film/sometitle/1/
https://letterboxd.com/username59/film/sometitle/2/
I want them all to display like this, without the username and without the trailing number if there is one:
https://letterboxd.com/film/sometitle/
✔ I can remove the trailing number, where it exists, with this:
=IF(REGEXMATCH(A2,"/film/(.*?)/\d/"), left(A2,len(A2)-2), A2)
result: https://letterboxd.com/username59/film/sometitle/
I have to be careful here because if a film's title is just a digit, I don't want it to be replaced, so I specified that there had to be content between /film/ and the trailing digit. (eg, I have to distinguish between film/9/ and film/sometitle/9/
✔ I can remove the username with this (although I'll probably have to also account for other types of characters, come to think of it):
=REGEXREPLACE(A2, regexextract(A2, "\/[A-Za-z0-9]+\/"),"/")
result: https://letterboxd.com/film/sometitle/2/
❌ But I can't for the life of me figure out how to combine both to do it all in one formula! I can perform one of the formulas on the results of the other one, but I can't combine to have it all done in one fell swoop. I've tried too many combinations to list here, but this one I thought was the most promising:
=REGEXREPLACE(A2, REGEXEXTRACT(IF(REGEXMATCH(A2,"/film/(.*?)/\d/"), left(A2,len(A2)-2), A2),"\/[A-Za-z0-9]+\/"),"/")
result: https://letterboxd.com/film/sometitle/2/
It didn't take care of the trailing 2/ and I don't know why. I'm guessing it's to do with some form of circularity? or the order of things?


