From: | Jasen Betts <jasen(at)xnet(dot)co(dot)nz> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Regular Expression Match Operator escape character |
Date: | 2010-12-13 09:18:29 |
Message-ID: | ie4od5$scs$5@reversiblemaps.ath.cx |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On 2010-12-08, Gnanakumar <gnanam(at)zoniac(dot)com> wrote:
> Hi,
>
> We're running PostgreSQL v8.2.3 on RHEL5.
>
> In some places in our application, we use Regular Expression Match Operator
> (~* => Matches regular expression, case insensitive) inside WHERE criteria.
>
> Example:
> SELECT ...
> FROM ...
> WHERE (SKILLS ~*
> '(^|\\^|\\||[^0-9|^a-z|^A-Z]|$)C#(^|\\^|\\||[^0-9|^a-z|^A-Z]|$)'
> OR SKILLS ~*
> '(^|\\^|\\||[^0-9|^a-z|^A-Z]|$).NET(^|\\^|\\||[^0-9|^a-z|^A-Z]|$)')
>
> In this case, we're trying to search/match for either "C#" OR ".NET" in
> SKILLS column.
>
> My question here is, do I need to escape the characters "#" and "." here?
yes. ( '.' especially, I don't think '#' has a special meaning in regex)
but as postgres uses posix extended regex simply escaping every non-letter
character is safe.
(^|\\^|\\||[^0-9|^a-z|^A-Z]|$)
seems to be another way to write
(^|$|[^0-9a-zA-Z])
both of which are locale dependant but that may not be an issue for you.
--
⚂⚃ 100% natural
From | Date | Subject | |
---|---|---|---|
Next Message | Viktor Bojović | 2010-12-13 23:36:57 | constraint with check |
Previous Message | Andreas Kretschmer | 2010-12-11 13:42:59 | Re: concatenate question |