I want to extract the url to download a file when user clicks on the image. the url of the image contains the url of the document as /Image/_Z_/Catalog_doc.jpg
Then user clicks I call a jQuery function fetchAndOpen(this)
In this method I would like to build proper file url i.e. : /Docs/Catalog.doc
So basically my issue is image extension (.jpg or .png or any other) second thing I want to remove /_Z_/
(this is hard coded predefined) and the last thing I want to replace _
with .
with the document extension.
Is there any regex or some simple solution of jQuery that can help me i know this can be easily done in javascript with substring
and lastIndexOf
methods but i expecting some thing with jquery / regex or other jquery based way out.
INPUT: /Image/Z/Catalog_doc.jpg -> OUTPUT: /Docs/Catalog.doc
Thanks.