0

I have a dynamic URL, which i want to append some string at last

 'http://staging.mydomain.name.com/test/7bb12c5f7b2f4f008261bea2d3f5abd2/200x200.png'

want to append "preview" before size (200x200.png which is also dynamic), something like below

'http://staging.mydomain.name.com/test/7bb12c5f7b2f4f008261bea2d3f5abd2/preview/200x200.png'

I have seen Javascript match to remove part of file name from URL - replace the last occurence but its not what i want.

Thanks

2 Answers 2

0

Just use a simple regular expression like:

'http://.../200x200.png'.replace(/[^\/]+$/, 'preview/$&')
Sign up to request clarification or add additional context in comments.

Comments

0

You can do like str.replace(/(/\d+x\d+.)/,'/preview$1')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.