Reputation: 11126
str = str.replace('?dfsdfsf=fdsfd.fdsfds/', 'uploads/')
i want to replace in url everything from '?' to first appearance of '/' afterwards ( including ) with 'uploads/'
i want to get https://websitename.com/uploads/d6113e4a-e789-44cd-8ba7-9684d29116dd.jpg
Upvotes: 2
Views: 7165
Reputation: 45589
var str = '?dfsdfsf=fdsfd.fdsfds/';
str = str.replace(/(\?[^\/]+\/)/, 'uploads/');
Upvotes: 2
Reputation: 101513
You'll need to use a regular expression for this.
Try:
str = str.replace(/\?(.+)\//i, 'uploads/');
Explanation:
\?
Finds the first ?
.
(.+)
Finds any amount of any non-newline character.
\/
Finds the last /
/i
Tells the regular expression to be case insensitive, just for good measure.
Upvotes: 3