Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 8A3A31337B39 for ; Mon, 13 Dec 2010 05:18:58 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 63168-09 for ; Mon, 13 Dec 2010 09:18:47 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from smtpcorp.com (smtpcorp.com [67.192.120.76]) by mail.postgresql.org (Postfix) with ESMTP id 21F3E13364DE for ; Mon, 13 Dec 2010 05:18:45 -0400 (AST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=smtpcorp.com; s=main; h=Content-Transfer-Encoding:Content-Type:Mime-Version:References:Message-ID:Date:Subject:From:To; bh=FVp9SizkNi+b4O5Lk1zNWeuYpP5lgjWFh/Wzp0o8xU8=; b=FxbQJ0fO4KrK8gaB1Z+4QYRA9Y9mXX7b1MN91rPdcOffHkH1r5sEKEU9CMV2CGkK1b66YQFIEpaeSNTwzIYFrpN9kpbBUkW6lsbAiRxv6OuXCfu++x8ZWQLp2+C/h9dq; Received: from ip-118-90-134-254.xdsl.xnet.co.nz ([118.90.134.254] helo=gonzo) by smtpcorp.com with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.70) id 1PS4YM-0004GC-F3; mid 144 for pgsql-sql@postgresql.org; Mon, 13 Dec 2010 09:18:42 +0000 Received: from news by gonzo with local (Exim 4.72) (envelope-from ) id 1PS4Y9-0007cS-DU for pgsql-sql@postgresql.org; Mon, 13 Dec 2010 22:18:29 +1300 To: pgsql-sql@postgresql.org Path: not-for-mail From: Jasen Betts Newsgroups: gmane.comp.db.postgresql.sql Subject: Re: Regular Expression Match Operator escape character Date: 13 Dec 2010 09:18:29 GMT Organization: Dis (not Dat) Organisation Lines: 36 Message-ID: References: <006601cb96df$0fd82cd0$2f888670$@com> NNTP-Posting-Host: localhost Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: reversiblemaps.ath.cx 1292231909 29084 127.0.0.1 (13 Dec 2010 09:18:29 GMT) X-Face: ?)Aw4rXwN5u0~$nqKj`xPz>xHCwgi^q+^?Ri*+R(&uv2=E1Q0Zk(>h!~o2ID@6{uf8s; a +M[5[U[QT7xFN%^gR"=tuJw%TXXR'Fp~W; (T"1(739R%m0Yyyv*gkGoPA.$b,D.w:z+<'"=-lVT?6 {T?=R^:W5g|E2#EhjKCa+nt":4b}dU7GYB*HBxn&Td$@f%.kl^:7X8rQWd[NTc"P"u6nkisze/Q; 8 "9Z{peQF,w)7UjV$c|RO/mQW/NMgWfr5*$-Z%u46"/00mx-,\R'fLPe.)^ User-Agent: slrn/pre1.0.0-18 (Linux) X-Smtpcorp-Track: 18216239.1.39441138 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-5 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201012/62 X-Sequence-Number: 34898 On 2010-12-08, Gnanakumar 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