Regular Expressions in JavaScript for URL Capture

前端 未结 4 1204
耶瑟儿~
耶瑟儿~ 2021-01-25 03:08

I am not too good with Regular Expressions in Javascript. Does anyone know an efficient way to capture the last portion of a URL???

I have the following URL:

<         


        
4条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-25 03:46

    You can use following code snippet

    var loc = location.href; 
    var lastPart = loc.substr(loc.lastIndexOf('/') + 1);
    

提交回复
热议问题