Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Postgresql regex replace numbers to asterisks

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

Thanks to @Wiktor Stribiżew:

SELECT regexp_replace('123467812345678', '(?<=..).(?=....)', '*','g');
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading