-1

I have text data as following in single column

This is a credit card number #341332123-432432-413213-13223. The CC # should be masked
This is a email #test@test.com The email address should be masked
This is a phone #555-555-5555, The phone number should be masked

I would like to replace the #{token} with mask(token)

e.g.

This is a credit card number mask(341332123-432432-413213-13223). The CC # should be masked
This is a email mask(test@test.com) The email address should be masked
This is a phone mask(555-555-5555), The phone number should be masked

Note. This is just text manipulation. I am not doing any masking in this step.

Saqib Ali
  • 3,953
  • 10
  • 55
  • 100

1 Answers1

0

You can use regexp_replace:

select regexp_replace(col_text, '(#)((?:[\d-]+)|(?:\w+@\w+\.\w+))', 'mask(\2)') from tbl

See fiddle.

Ajax1234
  • 69,937
  • 8
  • 61
  • 102
  • Not my down vote. But I would guess it is because you posted a code only answer. No explanation for it. – Belayer Oct 07 '22 at 17:59