Обсуждение: problem with regexp (cant quote +)

Поиск
Список
Период
Сортировка

problem with regexp (cant quote +)

От
peter pilsl
Дата:

postgres 7.3.2:

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';

thnx,
peter


--
IT-Consulting
mag. peter  pilsl
tel:+43-699-1-3574035
fax:+43-699-4-3574035
pilsl@goldfisch.at
http://www.goldfisch.at




Re: problem with regexp (cant quote +)

От
Alvaro Herrera
Дата:
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)