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
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 ($).