Re: why non-greedy modifier for one atom changesgreediness of other atoms?

From: "Albe Laurenz" <laurenz(dot)albe(at)wien(dot)gv(dot)at>
To: <depesz(at)depesz(dot)com>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: why non-greedy modifier for one atom changesgreediness of other atoms?
Date: 2010-01-04 14:38:23
Message-ID: D960CB61B694CF459DCFB4B0128514C203938105@exadv11.host.magwien.gv.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

hubert depesz lubaczewski wrote:
>> Example:
>> # select x, substring( x from E'^((.*?)(\\.[0-9]+))') from
>( values ('ab.123xxx.46hfd'),('a.b.c.d.123xx')) as q (x);
>> x | substring
>> -----------------+-----------
>> ab.123xxx.46hfd | ab.1
>> a.b.c.d.123xx | a.b.c.d.1
>> (2 rows)
>>
>>
>> I found in docs, that this is what happens, but I don't understand the
>> logic behind forcing unique greediness in whole expression.

Yes, that's odd.

>> Also - how can one write a regexp that will match "ab.123" and
>> "a.b.c.d.123" respectively?
>
>
> sorry - it could have be unclear - in case of string 'ab123bc.12xx'
> return value should be 'ab123bc.12' - i.e. we have to search to first .
> followed by digits and return it from beginning of string to the last of
> digits.

You could add a negative lookahead to exclude digits after the last match:

... substring(x from E'^(.*?\\.\\d+(?!\\d))') ...

Yours,
Laurenz Albe

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Chris Withers 2010-01-04 14:45:58 Re: how do I disable automatic start on mac os x?
Previous Message Sachin Srivastava 2010-01-04 14:38:00 Re: how do I disable automatic start on mac os x?