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

From Thomas Hallgren
Subject Re: Regexp matching: bug or operator error?
Date
Msg-id 41A3CAA6.7070100@mailblocks.com
Whole thread Raw
In response to Regexp matching: bug or operator error?  (Ken Tanzer <ktanzer@desc.org>)
List pgsql-general
Ken Tanzer wrote:
> 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.
>
The regexp {1,5} is satisfied with the minimum of 1 digit. It looks
ahead and finds your '.*'. That in turn consumes all but the last character.

Perhaps what you want is '[^0-9]+([0-9]{1,5})[^0-9]+'

Translates to "at least one non digit followed by 1-5 digits and then at
least 1 non digit".

Regards,
Thomas Hallgren

pgsql-general by date:

Previous
From: "Marc G. Fournier"
Date:
Subject: Re: Upcoming Changes to News Server ...
Next
From: Hunter Hillegas
Date:
Subject: Copying into Unicode - Correcting Errors