I need to check if given string is a palindrome using PostgreSQL. The first approach that came into my mind is to use a regex. I found a good regex example here.
The regex is: \A(?:(.)(?=.*?(\1\2?)\z))*?.?\2\z
.
It works just fine in my browser. But when I tried to apply it in PostgreSQL 11.2 (on Windows 10), it does not work as expected.
What I've tried so far:
Escaping backslashes (did not work):
select '23200000232' ~ '\\\\A(?:(.)(?=.*?(\\\\1\\\\2?)\\\\Z))*?.?\\\\2\\\\Z' as r;
Expected true, returned false.
Using special escaping syntax
E'...'
(did not work):select '23200000232' ~ E'\A(?:(.)(?=.*?(\1\2?)\Z))*?.?\2\Z' as r;
Expected true, returned false. Meanwhile
select '23200000232' ~ E'232(.)+232' as r;
returns true as expected;Executing
set standard_conforming_strings=on;
right before my query didn't help.Using small
\Z
and capital\Z
(according to the PostgreSQL regex documentation) to define end of a string didn't help.