0

I'm trying to assert a regex which matches any host and essentially match that the url ends in /profile/documents/<uuid>

This regex below matches exactly /profile/documents/<uuid> but how can I modify this regex to match anything that ends in /profile/documents/<uuid>?

expect(res.headers.location).to.match(/^\/profile\/documents\/[A-F\d]{8}-[A-F\d]{4}-4[A-F\d]{3}-[89AB][A-F\d]{3}-[A-F\d]{12}$/i) // Regex for /profile/documents/:uuid

Examples that'd i'd expect to match are:

http://localhost:3000/profile/documents/8ce825b7-b8c2-468b-a4c8-88eedea5b4c2
http://127.0.0.1/49943/profile/documents/8ce825b7-b8c2-468b-a4c8-88eedea5b4c2
Jack Bashford
  • 38,499
  • 10
  • 36
  • 67
Catfish
  • 17,019
  • 47
  • 183
  • 323
  • 1
    Marking this as duplicated doesn't help OP learn *why* they need (or don't need) this regex syntax. I wrote up an explanation about how OP is really asking about [URL Pathname](https://developer.mozilla.org/en-US/docs/Web/API/URL/pathname), but now I can't post it because of this aggressive "duplication" marking. – Sebastian Sangervasi Apr 12 '19 at 22:54

2 Answers2

3

Simple - just remove the ^ at the start. (This was matching the start of the string, so only the /profile/document/<uuid> would have been matched - removing it matches any string ending in /profile/document/<uuid>):

/\/profile\/documents\/[A-F\d]{8}-[A-F\d]{4}-4[A-F\d]{3}-[89AB][A-F\d]{3}-[A-F\d]{12}$/i
Jack Bashford
  • 38,499
  • 10
  • 36
  • 67
  • I thought that wasn't working. What wasn't working was that my dummy uuid was actually not matching correctly as I was using `11111111-1111-1111-1111-111111111111` – Catfish Apr 12 '19 at 22:19
  • I thought this not matching the examples that he has given – Blackjack Apr 13 '19 at 15:43
0

You can try this one .*\/profile\/documents\/[a-f\d]{8}-[A-f\d]{4}-4[A-f\d]{3}-[89ab][a-f\d]{3}-[a-f\d]{12}$

You can take a look for example in here regex-example

Blackjack
  • 870
  • 15
  • 34