pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Stephen Belcher <sycobuny@malkier.net>
To: Samuel Gendler <sgendler@ideasculptor.com>
Cc: andrew1 <andrew1@mytrashmail.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: question about reg. expression
Date: Wed, 19 Jan 2011 08:17:50 -0500
Message-ID: <AANLkTim9UYesBGU6fKf-sP6hcka8i45CyskKee9RPViJ@mail.gmail.com> (raw)
In-Reply-To: <AANLkTi=guS5T46M5wt7VXH8_0SfZ-_D+uG6Y=68FAFWJ@mail.gmail.com>
References: <ih58f7$63u$1@speranza.aioe.org>
	<AANLkTi=guS5T46M5wt7VXH8_0SfZ-_D+uG6Y=68FAFWJ@mail.gmail.com>

Another way to match multiple occurrences is to use curly brackets with a
number, like:
select 'ab' ~ '^[a-z]{2}$';

It can be done with a range of numbers as well:
select 'ab' ~ '^[a-z]{2,4}$';
select 'abab' ~ '^[a-z]{2,4}$';

I believe, however, that the curly brackets notation was introduced in 9.0
and is not available in earlier versions.

--Stephen

On Wed, Jan 19, 2011 at 5:21 AM, Samuel Gendler
<sgendler@ideasculptor.com>wrote:

> I'd think you need to indicate multiple alphabetic matches.  Your first
> regex actually matches only b followed by end of string and the second is
> really only matching start of string followed by a.  The third is looking
> for a single character string.
>
> Try this: select 'ab' ~ '^[a-z]+$'
> or this: select 'ab' ~ '^[a-z]*$'
>
> or if looking only for 2 character strings: select 'ab' ~ '^[a-z][a-z]$'
>
>
> On Tue, Jan 18, 2011 at 3:41 PM, andrew1 <andrew1@mytrashmail.com> wrote:
>
>> hi all,
>>
>> these return t:
>> select 'ab' ~ '[a-z]$'
>> select 'ab' ~ '^[a-z]'
>>
>> select 'ab' ~ '^[a-z]$' returns f
>>
>> Can't I use ^ and $ at the same time to match, in this case?
>> thanks.
>>
>> --
>> Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
>> To make changes to your subscription:
>> http://www.postgresql.org/mailpref/pgsql-sql
>>
>
>

view thread (5+ messages)  latest in thread

Message-ID: <AANLkTim9UYesBGU6fKf-sP6hcka8i45CyskKee9RPViJ@mail.gmail.com>
Permalink:  ../AANLkTim9UYesBGU6fKf-sP6hcka8i45CyskKee9RPViJ@mail.gmail.com/
Also on:    postgresql.org/message-id/AANLkTim9UYesBGU6fKf-sP6hcka8i45CyskKee9RPViJ@mail.gmail.com

 · 

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: pgsql-sql@postgresql.org
  Cc: sycobuny@malkier.net, sgendler@ideasculptor.com, andrew1@mytrashmail.com
  Subject: Re: question about reg. expression
  In-Reply-To: <AANLkTim9UYesBGU6fKf-sP6hcka8i45CyskKee9RPViJ@mail.gmail.com>

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

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