greedy or not? regexps...

From: "Anton Melser" <melser(dot)anton(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: greedy or not? regexps...
Date: 2007-02-23 09:11:55
Message-ID: 92d3a4950702230111v5abcde0fg96117486623306db@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,
I am trying to understand the function substring.

Here:
select SUBSTRING(cit1.summary, '=([0-9]*)') from cms_items cit1
where cit1.summary ~* '.*linkadministration.*[0-9]*';

gives me two empty strings and

select SUBSTRING(cit1.summary, '=([0-9]{1,10})') from cms_items cit1
where cit1.summary ~* '.*linkadministration.*[0-9]*';

gives me the right values.

However, bizarrely,

select SUBSTRING(ban1.url_id, '=([0-9]*)')
from banner ban1
where ban1.url_id ~* '.*linkadministration.*[0-9]*';

select SUBSTRING(ban1.url_id, '=([0-9]{1,10})')
from banner ban1
where ban1.url_id ~* '.*linkadministration.*[0-9]*';

Both give me the same result!!! The difference being that in case two
the numbers I am catching are at the end of the strings and in case 1
in the middle. Is this normal? Which is correct?
Cheers
Anton

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ben Edwards 2007-02-23 09:23:56 Writing oracle/postgress generic SQL
Previous Message Alban Hertroys 2007-02-23 09:01:46 Re: complex referential integrity constraints