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

Postgres SQL to remove only non-ascii characters from a string

We have data in Postgres something as below , there is possibility of having mutiple non-ascii chars in a string

Name
Kate SolutionǸǸs
Etak Solutions

We are trying to identify if there are any NON-ASCII char set from the string and remove all of them if there are any(if there no non-ascii then keep the string as is) and expecting output below output

Name
Kate Solutions
Etak Solutions

Tried using below SQL but its just removing only one non-ascii char irrespective of the position where it is present

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

select REGEX_REPLACE(name,'[^ -~]', '') as new_name from table

Appreciate any help!

>Solution :

From the Postgresql documentation:

If the g flag is given, or if N is specified and is zero, then all matches at or after the start position are replaced. (The g flag is ignored when N is specified.)

So either add a 4th parameter as zero, 0, or add a 6th parameter as ‘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