regexp should not end with both explicit end-slash and optional end-slash

Author: iambumbleheadCreated Apr 23, 2026Updated Jun 11, 2026

Hello and thanks for this package. When the original path ends with an end-slash (ex '/about/') the returned regexp ends with both a required and an optional end-slash; I believe, instead, it should end with only one end-slash; optional or required.

Instead of this,

javascript
pathToRegexp('/about/').regexp // /^(?:\/about\/)(?:\/$)?$/i

One of these would be better,

javascript
pathToRegexp('/about/').regexp // /^(?:\/about)(?:\/$)?$/i
pathToRegexp('/about/').regexp // /^(?:\/about\/)$/i