AM Scripting Regex Error

In a journey, i have a need to mask the email address (and phone) of the user. I wrote a javascript to do this but when invoking this in the journey i am getting an exception on the regex part of the script. Is there a way to run the below function, specifically the regex variable / replace) in AM?


//this will mask the email address value
function maskEmailAddress(mail) {
  logger.error("Masking the email address with value: " + mail)
  var rawUser, maskedUser, rawDomain, retMail
  var regex = /(?<!^).(?!$)/g
  rawUser = mail.split("@")[0]
  rawDomain = mail.split("@")[1]
  maskedUser = rawUser.replace(regex, "*")
  retMail = maskedUser + "@" + rawDomain
  logger.error("Returning the value for masked mail of: " + retMail)
  return retMail
}

this script works in node / straight java script, but trying to find the right syntax for am script / rhino.

Thanks
Nick

Hi Nick,

maybe you can remove regex and use repeat and length for this use case:
maskedUser = rawUser.replace(regex, " ")
by
maskedUser = “*”.repeat(rawUser.length)

Yeah, thought of doing that but I also have a use case to do telephone with a similar pattern and it is giving me an error. I need to be able to do first / last character (based on the regex above and * for everything in between. Looking at the scripting notes for AM at Sample scripts :: AM 7.2.2 (forgerock.com) they have the same pattern so not sure why mine is not working.

Nick