Linked Questions

Popular Questions

Extract a substring from value of key-value pair using regex

Asked by At

I have a string in log and I want to mask values based on regex.

For example:

"email":"[email protected]", "phone":"1111111111", "text":"sample text may contain email [email protected] as well"

The regex should mask

  1. email value - both inside the string after "email" and "text"
  2. phone number

Desired output:

"email":"*****", "phone":"*****", "text":"sample text may contain email ***** as well"

What I have been able to do is to mask email and phone individually but not the email id present inside the string after "text".

Regex developed so far:

(?<=\"(?:email|phone)\"[:])(\")([^\"]*)(\")

https://regex101.com/r/UvDIjI/2/

Related Questions