Validating user-input to be inserted in regular expressions

From: Vincenzo Ciancia <vincenzo_yahoo_addressguard-gmane(at)yahoo(dot)it>
To: pgsql-general(at)postgresql(dot)org
Subject: Validating user-input to be inserted in regular expressions
Date: 2005-01-24 14:55:21
Message-ID: ct328q$4ms$1@sea.gmane.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi all,

I would like to take user input, which should be interpreted literally, and
put it inside a regular expression, something like

select * from files where path ~ (USER_INPUT || '.*')

How should I escape the user input? I mean: I know that I must insert double
backslashes before special characters (in the sense of regular expressions)
but how to know what these special characters are? Should I find every
possible character in the documentation for regular expressions? Is there a
safer way?

Thanks

Vincenzo Ciancia

--
Please note that I do not read the e-mail address used in the from field but
I read vincenzo_ml at yahoo dot it
Attenzione: non leggo l'indirizzo di posta usato nel campo from, ma leggo
vincenzo_ml at yahoo dot it

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Richard_D_Levine 2005-01-24 14:59:29 Re: SCHEMA compatibility with Oracle/DB2/Firebird
Previous Message Frank D. Engel, Jr. 2005-01-24 14:49:45 Re: Data entry - forms design or other APIs etc. - what is there?