Remove everything after last backslash

前端 未结 3 655
滥情空心
滥情空心 2021-02-02 05:41

var t = \"\\some\\route\\here\"

I need \"\\some\\route\" from it.

Thank you.

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-02 06:30

    As stated in @Archer's answer, you need to double up on the backslashes. I suggest using regex replace to get the string you want:

    var t = "\\some\\route\\here";
    t = t.replace(/\\[^\\]+$/,"");
    alert(t);
    

提交回复
热议问题