remove everything before the last occurrence of a character

前端 未结 5 1320
执念已碎
执念已碎 2020-12-13 23:34

I\'m trying to perform the following action on a string :

  • find the last occurrence of the character \"/\";
  • remove everything before that
5条回答
  •  离开以前
    2020-12-14 00:16

        var result = /\/([^\/]*)$/.exec(location)[1];
    
    //"remove-everything-before-the-last-occurrence-of-a-character#10767835"
    

    Note: location here is the window.location, not your var location.

提交回复
热议问题