Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id BECFE1337B58 for ; Wed, 19 Jan 2011 09:43:49 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 22471-07 for ; Wed, 19 Jan 2011 13:43:43 +0000 (UTC) X-Greylist: delayed 00:25:47.78874 by SQLgrey-1.7.6 Received: from mail-iy0-f174.google.com (mail-iy0-f174.google.com [209.85.210.174]) by mail.postgresql.org (Postfix) with ESMTP id 0F7531337B39 for ; Wed, 19 Jan 2011 09:43:40 -0400 (AST) Received: by iyj18 with SMTP id 18so822345iyj.19 for ; Wed, 19 Jan 2011 05:43:41 -0800 (PST) MIME-Version: 1.0 Received: by 10.42.169.131 with SMTP id b3mr825876icz.125.1295443070771; Wed, 19 Jan 2011 05:17:50 -0800 (PST) Received: by 10.42.5.74 with HTTP; Wed, 19 Jan 2011 05:17:50 -0800 (PST) In-Reply-To: References: Date: Wed, 19 Jan 2011 08:17:50 -0500 Message-ID: Subject: Re: question about reg. expression From: Stephen Belcher To: Samuel Gendler Cc: andrew1 , pgsql-sql@postgresql.org Content-Type: multipart/alternative; boundary=90e6ba6e8b700f63d3049a32d8a3 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.599 tagged_above=-5 required=5 tests=BAYES_00=-1.9, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_LOW=-0.7 X-Spam-Level: X-Archive-Number: 201101/52 X-Sequence-Number: 34999 --90e6ba6e8b700f63d3049a32d8a3 Content-Type: text/plain; charset=ISO-8859-1 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 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 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 >> > > --90e6ba6e8b700f63d3049a32d8a3 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Another way to match multiple occurrences is to use curly brackets with a n= umber, 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 b= elieve, 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 Gend= ler <sgen= dler@ideasculptor.com> wrote:
I'd think you need to indicate multiple alphabetic matches. =A0Your fir= st regex actually matches only b followed by end of string and the second i= s really only matching start of string followed by a. =A0The third is looki= ng for a single character string.

Try this:=A0select 'ab' ~ '^[a-z]+$'
or this:=A0select 'ab' ~ '^[a-z]*$'

=
or if looking only for 2 character strings:=A0select 'ab' ~ &#= 39;^[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


--90e6ba6e8b700f63d3049a32d8a3--