Re: Regexp matching: bug or operator error? - Mailing list pgsql-general

From Tom Lane
Subject Re: Regexp matching: bug or operator error?
Date
Msg-id 1713.1101254499@sss.pgh.pa.us
Whole thread Raw
In response to Regexp matching: bug or operator error?  (Ken Tanzer <ktanzer@desc.org>)
Responses Re: Regexp matching: bug or operator error?
List pgsql-general
Ken Tanzer <ktanzer@desc.org> writes:
> Using Postgres V. 7.4.1, the following query:

>     SELECT substring('X12345X' FROM '.*?([0-9]{1,5}).*?');

> Returns '1'.  I would expect it to return '12345'.  Is this a bug, or am
> I missing something?  Thanks.

Hmm ... playing with it, it seems that there may indeed be a bug here
... it's acting like the "non greedy" flag from the .*? is being applied
to the {m,n} as well.  In other words the behavior would be correct for

     SELECT substring('X12345X' FROM '.*?([0-9]{1,5}?).*?');

However, aren't you doing this the hard way?  Why not just

    SELECT substring('X12345X' FROM '([0-9]{1,5})');

            regards, tom lane

pgsql-general by date:

Previous
From: Hunter Hillegas
Date:
Subject: Copying into Unicode - Correcting Errors
Next
From: Tom Lane
Date:
Subject: Re: Regexp matching: bug or operator error?