Re: BUG #1687: Regular expression problem (II)

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Halley Pacheco de Oliveira" <halleypo(at)yahoo(dot)com(dot)br>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #1687: Regular expression problem (II)
Date: 2005-05-31 15:13:08
Message-ID: 12383.1117552388@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

"Halley Pacheco de Oliveira" <halleypo(at)yahoo(dot)com(dot)br> writes:
> Maybe it would be easier to see the the problem I'm having with regular
> expressions this way:

> Maybe it would be easier to see the the problem I'm having with regular
> expressions this way:

> SELECT '192.168.0.15' SIMILAR TO
> '([[:alnum:]_-]+).([[:alnum:]_-]+).([[:alnum:]_]+)';
> ?column?
> ----------
> t

> SELECT '192.168.0.15' SIMILAR TO '([\\w-]+).([\\w-]+).([\\w]+)';
> ?column?
> ----------
> f

SIMILAR TO patterns are required to match the whole data string; so
the above fails because it only matches 3 digit groups not 4. The
others all fail because you put explicit ^ and $ into them.

The reason the first one works is that you put _ into the pattern, which
means "match anything" in SIMILAR-TO land; so it gets translated to "."
to be fed to the regular regexp engine. (Arguably that should not
happen inside square brackets, but similar_escape() isn't smart enough
to distinguish.) And that makes it possible for one of the
[]-expressions to match two digit groups plus the intervening dot.

regards, tom lane

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Alvaro Herrera 2005-05-31 15:15:23 Re: BUG #1686: Regular expression problem
Previous Message Haluk GÜNÇER 2005-05-31 07:54:29 Re: BUG #1678: pw_shadow BUS ERROR