I am trying to use a foldLeft to replace user names with a hidden value and print them out
private def removeNamesFromErrorMessage(errorMessage: String): Unit = {
val userNames = List("mary", "john")
val errorMessage = "users mary and john have not paid their fee "
val newError = userNames.foldLeft(errorMessage)((message, name) => message.replaceAll(s"${name}:\\s?[a-zA-Z0-9-_.]+", s"${name}: <HIDDEN USER>"))
println(newError)
}
However it is still printing out the user names and I am getting an error on message.replaceAll
, saying:
Anchor '$' in unexpected position