middleware: Use regular expressions to match IDs

Issue #299.
Merge branch 'issue/299'