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