I am trying to replace all instances of - in my GUID using SSJS in Marketing Cloud.

var job_guid = 'aad2c93e-0e3e-4ec5-8592-f4ff510c1d94';
var stripped_guid = job_guid.replace('-', '');
Write('giud:' + job_guid + '<br>');
Write('stripped_guid:' + stripped_guid + '<br>');

The code above only seems to replace the first instance of - but not the rest.


Is there something I'm missing?


Figured it out, need to use the regex modifier g to replace all instead of the first instance.

var stripped_guid = job_guid.replace(/-/g, '');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.