React Router Dom v5 : regex path of a GUID / UUID is not recognised

Viewed 1309

react-router-dom version 5.1.2


Example route:

/user/:guid

Example guid:

2d88abfd-35a2-4481-91c9-800ecc67b346

Example route with guid regex:

/user/:guid([0-9a-f]{8}-([0-9a-f]{4}\-){3}[0-9a-f]{12})

I'm unable to get a match with the above. To test my sanity to see if basic regex paths work, I did a simple number only regex, that works fine, maybe I'm not escaping correctly?

1 Answers

It looks as though the pattern in the react router cannot contain inner grouping constructs.

They mention that "(?: will be allowed to be nested in the next major release."

So, probably, you will be able to use

/user/:guid([0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12})
                       ^^^^^^^^^^^^^^^^^^^

If this is not implemented in your version, just repeat the pattern part you quantified:

/user/:guid([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^    
Related