Re: question about reg. expression

From: Stephen Belcher <sycobuny(at)malkier(dot)net>
To: Samuel Gendler <sgendler(at)ideasculptor(dot)com>
Cc: andrew1 <andrew1(at)mytrashmail(dot)com>, pgsql-sql(at)postgresql(dot)org
Subject: Re: question about reg. expression
Date: 2011-01-19 13:17:50
Message-ID: AANLkTim9UYesBGU6fKf-sP6hcka8i45CyskKee9RPViJ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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(at)ideasculptor(dot)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(at)mytrashmail(dot)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(at)postgresql(dot)org)
>> To make changes to your subscription:
>> http://www.postgresql.org/mailpref/pgsql-sql
>>
>
>

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Kenneth Marshall 2011-01-19 14:18:38 Re: question about reg. expression
Previous Message Samuel Gendler 2011-01-19 10:21:07 Re: question about reg. expression