Re: Regexp matching: bug or operator error?

From: Thomas Hallgren <thhal(at)mailblocks(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Regexp matching: bug or operator error?
Date: 2004-11-23 23:41:26
Message-ID: 41A3CAA6.7070100@mailblocks.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs 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

In response to

Browse pgsql-docs by date

  From Date Subject
Next Message Tom Lane 2004-11-24 00:01:39 Re: Regexp matching: bug or operator error?
Previous Message Ken Tanzer 2004-11-23 23:24:54 Regexp matching: bug or operator error?

Browse pgsql-general by date

  From Date Subject
Next Message Hunter Hillegas 2004-11-23 23:56:59 Copying into Unicode - Correcting Errors
Previous Message Marc G. Fournier 2004-11-23 23:36:06 Re: Upcoming Changes to News Server ...