javascript - How to return filename without any extensions? -


i using following code below filename url, when there # , number, doest not work completely. how can filename returns "somefilename" or "somename" ? examples of various scenarios

fileformats examples

     1. www.something.com/somefilename.html#108 or      2. www.someting.com/group//somename.shtml or      3. www.something.com/group/somename#1011 

jasvascript

   $(document).ready(function() {      var url=window.location.href;      var filename = url.substring(url.lastindexof('/')+1);      alert(" filename " +filename);      var cleanfilename =filename.slice(0, -5)      alert(" cleanfilename" +cleanfilename);     alert($('#business-type :selected').val());     $('select[id^="business-type"] option[value='+cleanfilename+']').attr("selected","selected");       }); 

i'd go for

var filename = document.location.pathname.match(/([^/]*?)(?:\..*)?$/)[1] 

Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -