public inbox for [email protected]  
help / color / mirror / Atom feed
From: Thomas Hallgren <[email protected]>
To: [email protected]
Subject: Re: Regexp matching:  bug or operator error?
Date: Wed, 24 Nov 2004 00:41:26 +0100
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>

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




view thread (12+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: Regexp matching:  bug or operator error?
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox