0

I use Postgresql and need to replace numbers to asterisk at database layer. Howerver I'm new to learn regex and seems to be hard to do this with my current knowledge.

I will have in my database 16 numbers varchar and I need to replace middle numbers with asterisk.

Example. 123467812345678 -> 12**********5678

Could someone tell me how regex for this should look like in postgresql ? Thanks in advance

2
  • 1
    (?<=..).(?=....) Commented Sep 19, 2022 at 14:40
  • see also regex101.com Commented Sep 19, 2022 at 14:41

1 Answer 1

0

Thanks to @Wiktor Stribiżew:

SELECT regexp_replace('123467812345678', '(?<=..).(?=....)', '*','g');
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Wiktor and Frank. It solves my problem

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.