I have a web API that has to log the request body if an exception happens.
Since there are first name and last name properties in the body, I have to anonymize them which I'm trying to achieve using regex.
requestBody = Regex.Replace(requestBody, @"""FirstName"":""(.+)""", match => $@"""FirstName"":""{match.Groups[1].ToString()[0]}***""");
requestBody = Regex.Replace(requestBody, @"""LastName"":""(.+)""", match => $@"""LastName"":""{match.Groups[1].ToString()[0]}***""");
Unfortunately, after the first replace, everything else in the request body is gone (probably due to the .+
but shouldn't this stop when it finds the first "
?
A request body looks like that:
{ Person":{"Gender":"Male","FirstName":"Aaron","LastName":"Example","BirthDate":"1990-09-02T00:00:00.000Z" }}
And I want the first name to be "A***" and the last name to be "E***".
What am I doing wrong and is there a more elegant way?
Thanks in advance!