Regular Expressions in JavaScript for URL Capture

前端 未结 4 1249
耶瑟儿~
耶瑟儿~ 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:45

    There are built in methods for this:

    window.location.pathname.split("/").pop()
    

    This will get everything after the domain name (window.location.pathname), then split it by forward slashes (split("/")), then return the last item of the array returned by split(), (pop()).

提交回复
热议问题