in reply to Re: postgres reg expression quoting
in thread postgres reg expression quoting

none of the above answers my question. if user enters '[' for their search query for example I get "ERROR: invalid regular expression: brackets [] not balanced"

what I need is a double backlash before every unsafe character

Replies are listed 'Best First'.
Re^3: postgres reg expression quoting
by BrowserUk (Patriarch) on Apr 01, 2009 at 14:15 UTC

      that smells like a solution, quotemeta will add '\' to all non word characters and then during execution that '\' will get quoted to make it '\\' so postgress is happy

Re^3: postgres reg expression quoting
by ikegami (Patriarch) on Apr 01, 2009 at 14:31 UTC

    That's odd. There's nothing variable in what you presented, so how can any of it be from the user?

    Please don't post one piece of code and ask about another.

      of course there is.. what about the placeholder '?' ;-)

        My apologies. I didn't look at the expression closely enough and jumped to the wrong conclusion. I have a better understanding of it now.

        If you're expecting the user to provide text to match literally (as opposed to a regular expression pattern), then you need to convert the text into a regular expression pattern. In Perl, quotemeta would do. It will probably do for your database as well.

        my $input = '['; $sth->execute(quotemeta($input));