JS remove everything after the last occurrence of a character

前端 未结 9 1868
梦如初夏
梦如初夏 2020-12-11 16:47

Okay I have this

var URL = \"http://stackoverflow.com/questions/10767815/remove-everything-before-the-last-occurrence-of-a-character\";
console.log(URL.subst         


        
9条回答
  •  半阙折子戏
    2020-12-11 17:39

    Try this jsfiddle or run the code snippet.

        var URL = "http://stackoverflow.com/questions/10767815/remove-everything-before-the-last-occurrence-of-a-character";
        var myRegexp = /^(.*\/)/g;
        var match = myRegexp.exec(URL);
        alert(match[1]); 

提交回复
热议问题