Regex Path Matching
Unanswered
Nile Crocodile posted this in #help-forum
Nile CrocodileOP
I have a path structure that includes a uuid as a second path component with optional further path components e.g. "/users/854bd2ff-c967-4c30-a5c9-67ea6f6f1469" and "/users/854bd2ff-c967-4c30-a5c9-67ea6f6f1469/edit". I am trying to validate the uuid for all paths using regex path matching in my next.config and redirect in all cases in which the uuid fails validation. The following will match if the uuid is invalid but doesn't match when additional characters are appended e.g. "/users/854bd2ff-c967-4c30-a5c9-67ea6f6f1469-" won't match:
"/users/:uuid((?![0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}).*)"
Presumably, this is due to the ".*" at the end but without it, no matching takes place. If the uuid is valid, the only characters allowed to be directly appended to it would be "/" and "?" followed by any string.
I am able to achieve the desired matching using regular regex using the following:
^(?![0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}(/|?|$)).*$ (not sure this is the best way)
Unfortunately, I haven't been able to get this working in my next.config because it doesn't like the "(/|?|$)" capturing group. Any ideas how this can be achieved?
"/users/:uuid((?![0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}).*)"
Presumably, this is due to the ".*" at the end but without it, no matching takes place. If the uuid is valid, the only characters allowed to be directly appended to it would be "/" and "?" followed by any string.
I am able to achieve the desired matching using regular regex using the following:
^(?![0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}(/|?|$)).*$ (not sure this is the best way)
Unfortunately, I haven't been able to get this working in my next.config because it doesn't like the "(/|?|$)" capturing group. Any ideas how this can be achieved?