I want to match a list of special characters ('-&
) for a postgresql query. Through an online regex editor I came to the pattern [\'\-\&\\]
. But when I use that in my query I get an syntax error:
connection.execute("SELECT index, name FROM test21 WHERE test21.name ~ '[\'''\-\&\\]'")
results ins
ProgrammingError: (ProgrammingError) syntax error at or near "\"
LINE 1: test21 WHERE test21.name ~ '['''\-\&\]'
^
I found other answers, like https://stackoverflow.com/a/25925429/380038, but these match all special characters.