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

From: hubert depesz lubaczewski <depesz(at)depesz(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: why non-greedy modifier for one atom changes greediness of other atoms?
Date: 2010-01-04 10:49:22
Message-ID: 20100104104922.GC21870@depesz.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Jan 04, 2010 at 11:30:51AM +0100, 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.
>
> 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.

Best regards,

depesz

--
Linkedin: http://www.linkedin.com/in/depesz / blog: http://www.depesz.com/
jid/gtalk: depesz(at)depesz(dot)com / aim:depeszhdl / skype:depesz_hdl / gg:6749007

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message donniehan 2010-01-04 11:04:59 Some issues about data type convert
Previous Message hubert depesz lubaczewski 2010-01-04 10:30:51 why non-greedy modifier for one atom changes greediness of other atoms?