Q:

Filter out trailing slash type URL with regex

I want to capture www.example.com/stuff/morestuff from the following list:
www.example.com/stuff/morestuff
www.example.com/stuff/morestuff/
www.example.com/stuff/morestuff///

I was trying this regex:
^(.*)(?:\/)*$

A:

Placing a ? after a *, makes it non-greedy, i.e. it stops consuming characters as early as possible. In this case:
^(.*?)(?:\/)*$

it will consume only up till the first slash.
Depending on the regex implementation you may not have to escape the forward slash.

