m! #start match /? # 0 or 1 '/' ( # start capture $1 [^/] #consisting of no '/' characters + # 1 or more times $ # until and including eol (?) ) # end capture $1 ! # end match