pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedRegular Expression Match Operator escape character
2+ messages / 2 participants
[nested] [flat]
* Regular Expression Match Operator escape character
@ 2010-12-08 13:51 Gnanakumar <gnanam@zoniac.com>
2010-12-13 09:18 ` Re: Regular Expression Match Operator escape character Jasen Betts <jasen@xnet.co.nz>
0 siblings, 1 reply; 2+ messages in thread
From: Gnanakumar @ 2010-12-08 13:51 UTC (permalink / raw)
To: pgsql-sql
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?
Regards,
Gnanam
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Regular Expression Match Operator escape character
2010-12-08 13:51 Regular Expression Match Operator escape character Gnanakumar <gnanam@zoniac.com>
@ 2010-12-13 09:18 ` Jasen Betts <jasen@xnet.co.nz>
0 siblings, 0 replies; 2+ messages in thread
From: Jasen Betts @ 2010-12-13 09:18 UTC (permalink / raw)
To: pgsql-sql
On 2010-12-08, Gnanakumar <gnanam@zoniac.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
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2010-12-13 09:18 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2010-12-08 13:51 Regular Expression Match Operator escape character Gnanakumar <gnanam@zoniac.com>
2010-12-13 09:18 ` Jasen Betts <jasen@xnet.co.nz>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox