Regex to match URL end-of-line or “/” character

前端 未结 4 1674
闹比i
闹比i 2020-12-08 17:58

I have a URL, and I\'m trying to match it to a regular expression to pull out some groups. The problem I\'m having is that the URL can either end or continue with a

4条回答
  •  温柔的废话
    2020-12-08 18:42

    In Ruby and Bash, you can use $ inside parentheses.

    /(\S+?)/(\d{4}-\d{2}-\d{2})-(\d+)(/|$)
    

    (This solution is similar to Pete Boughton's, but preserves the usage of $, which means end of line, rather than using \z, which means end of string.)

提交回复
热议问题