Re: problem with regexp (cant quote +) - Mailing list pgsql-general

From Alvaro Herrera
Subject Re: problem with regexp (cant quote +)
Date
Msg-id 20030705205334.GB17982@dcc.uchile.cl
Whole thread Raw
In response to problem with regexp (cant quote +)  (peter pilsl <pilsl@goldfisch.at>)
List pgsql-general
On Sat, Jul 05, 2003 at 04:46:47PM +0200, peter pilsl wrote:
>
> I wonder why the following expression fails. I came to this wondering why I
> could not search for + using the '~'-operator.
>
> select 'ok' where 'H+H'~'H\+H';

You need to double the backslash, because the first one is going away at
parse time (you need a literal \ for the regex).

alvh=> select 'ok' where 'H+H' ~ 'H\\+H';
 ?column?
----------
 ok
(1 row)

Yeah, annoying, but easily understood.  Other tools behave the same:
$ echo 'H+H' | egrep H+H
$ echo 'H+H' | egrep H\+H
$ echo 'H+H' | egrep H\\+H
H+H

--
Alvaro Herrera (<alvherre[a]dcc.uchile.cl>)
"I dream about dreams about dreams", sang the nightingale
under the pale moon (Sandman)

pgsql-general by date:

Previous
From: Tino Wildenhain
Date:
Subject: Re: problem with regexp (cant quote +)]
Next
From: "Robert Wille"
Date:
Subject: Re: Record locking in deadlock