Substr from specific character

Solved!
I have a string and I want to cut off a specific part. The string looks like this:

https://static.wixstatic.com/media/9307f1_2a682e7365e3407b85a6c3f4b4f45f00~mv2.png/1125_2000/9307f1_2a682e7365e3407b85a6c3f4b4f45f00~mv2.png

I want to cut it so that it looks like this:

https://static.wixstatic.com/media/9307f1_2a682e7365e3407b85a6c3f4b4f45f00~mv2.png

So I need to remove this:

/1125_2000/9307f1_2a682e7365e3407b85a6c3f4b4f45f00~mv2.png

This basically means I have to find the fifth slash in the string, and remove everything from that point on. Any way I can do that?

Perhaps:

let imageSRC = "Enter Full URL Here";
let firstCut = imageSRC.substr(0, imageSRC.lastIndexOf('/'));
let secondCut = firstCut.substr(0, firstCut.lastIndexOf('/'));
console.log(secondCut);

Wow, that works like a charm!! Thank you!

Thanks!

The code above worked great for me to replace the “&” character with the word “and” in my page element variables. I probably didn’t make the code very efficient, but it works great.

let tempCompany = $w( ‘#companyname’ ).value;
var newCompany = tempCompany.replace(/&/ g , ‘and’ );
$w( ‘#companyname’ ).value = String(newCompany);

FYI, I needed to replace the & character because the SendGrid email system was cutting off the body of the email message as soon as there was an &.

Although this is an old post, thanks for sharing. Code looks efficient enough to me.

Interesting about SendGrid cutting of the body of the email message. I’m not sure of the format of that field, but you might be able to use the & by using an escape character or an HTML entity.