sqlregexoracle-database

regex_replace function


I'm trying to replace the following string with offset of 2 characters from beginning and end.

Example input: A9999999999

Expected output: A9********99

I have tried the following but not able to narrow down to exact format


Solution

  • REGEXP_REPLACE('A9999999999', '(.{2}).*(.{2})', '\1*******\2')

    based on you examples, it looks like your string will always be the same length.

    I select the first and last characters in capture groups and use those in the final string