Skip to content

Instantly share code, notes, and snippets.

@DerexScript
Created July 12, 2021 21:09
Show Gist options
  • Save DerexScript/b4b2bb7e9faeddfaef320cf2a5fdf015 to your computer and use it in GitHub Desktop.
Save DerexScript/b4b2bb7e9faeddfaef320cf2a5fdf015 to your computer and use it in GitHub Desktop.
function str_replace_last(search, replace, str){
let pos = str.lastIndexOf('webp');
let search_length;
if(pos != -1){
search_length = search.length;
str = str.substring(0, pos)+replace+str.substring(pos+search_length);
}
return str;
}
str_replace_last("webp", "jpg", "22708867webp360e747bwebp444651.webp");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment