Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove first folder in string

Tags:

javascript

I have a folder path that always starts with a certain string which I want to remove. Let's say it looks like this:

my-bucket/2929023/32822323/file.jpg

I want it to look like this:

2929023/32822323/file.jpg

How would I do that?

like image 378
Tometoyou Avatar asked Oct 21 '25 05:10

Tometoyou


1 Answers

You could use a simple replace method if the string is only present once;

var string = "my-bucket/2929023/32822323/file.jpg";

var revisedString = string.replace('my-bucket/', '');

console.log(revisedString);

However, you're also able to use a Regex (regular expression) to remove it as well, something like;

var string = "my-bucket/2929023/32822323/file.jpg";

console.log(string.replace(/^my-bucket\//, ''));
like image 130
Simon R Avatar answered Oct 24 '25 05:10

Simon R



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!