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

前端 未结 4 1680
闹比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:37

    You've got a couple regexes now which will do what you want, so that's adequately covered.

    What hasn't been mentioned is why your attempt won't work: Inside a character class, $ (as well as ^, ., and /) has no special meaning, so [/$] matches either a literal / or a literal $ rather than terminating the regex (/) or matching end-of-line ($).

提交回复
热议问题