2

I have URLs like this:

http://some.bunch.of.subdomains.hostname.tld/somepath/deeper/GUID/foo/bar/candy

GUID is the ID I need to find and replace.

The GUID is stripped, no dashes, exactly 32 characters, lowercase a-f, 0-9. Like this:

961b7d0e50f0462a8828c31bf0874a71

After I find it, I will replace it like this:

document.URL.replace(/regexp goes here/, 'newGUID');
DominiqueBal
  • 787
  • 1
  • 7
  • 18

2 Answers2

2

You could try something like:

str.replace(/\b[a-f\d]{32}\b/, 'newGUID');
Qtax
  • 33,241
  • 9
  • 83
  • 121
  • Can you explain the `a-z\d` part please? Note that GUID only contains characters from A to F in the alphabet and no more. – DominiqueBal Mar 09 '12 at 21:03
  • My bad, thought you said a-z, updated. `lowercase a-f, 0-9` is what `[a-f\d]` matches, `\d` is same as `[0-9]`, just shorter. – Qtax Mar 09 '12 at 21:08
1

For regular GUID adapting from this answer https://stackoverflow.com/a/13653180/8443908

'd3aa88e2-c754-41e0-8ba6-4198a34aa0a2'.replace(/\b[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\b/, 'newGUID');