Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Searching For Special Characters in postgresql

i am trying to find rows in a postgresql table where a specific column contains special characters excluding the following @^$.!\-#+'~_

any help appreciated

like image 286
zarek37 Avatar asked Oct 14 '25 08:10

zarek37


1 Answers

Hi I think I figured it out. I found a solution that worked for me using Posix Regular Expressions.

SELECT *
FROM TABLE_NAME
WHERE fieldName ~ '[^A-Za-z0-9@^\\$.!\-#+~_]'

The regular expression matches any character that is not between A-Z, a-z, 0-9 and is also not any of your whitelisted characters ^$.!-#+~_. Notice that in the regex I had to escape the backslash and the hyphen, because they have a special meaning in regex. Maybe start by evaluating my proposed regex online with a few examples, e.g. here: https://regex101.com

like image 178
yezper Avatar answered Oct 17 '25 01:10

yezper



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!