简体   繁体   中英

javascript match and add string in dynamic Url

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

只需使用一个简单的正则表达式即可:

'http://.../200x200.png'.replace(/[^\/]+$/, 'preview/$&')

你可以像str.replace(/(/ \\ d + x \\ d +。)/,'/ preview $ 1')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM