It turns out that this is a bug from Java 8 (link). Also see this mailing discussion.
The solution is to update the regex. ChatGPT suggests ^(/[-a-zA-Z0-9_.]+)+/?$
^(/[-a-zA-Z0-9_.]+)+/?$