pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
question about reg. expression
5+ messages / 5 participants
[nested] [flat]

* question about reg. expression
@ 2011-01-18 23:41 andrew1 <andrew1@mytrashmail.com>
  2011-01-19 10:21 ` Re: question about reg. expression Samuel Gendler <sgendler@ideasculptor.com>
  2011-01-22 08:59 ` Re: question about reg. expression Jasen Betts <jasen@xnet.co.nz>
  0 siblings, 2 replies; 5+ messages in thread

From: andrew1 @ 2011-01-18 23:41 UTC (permalink / raw)
  To: pgsql-sql

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.



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: question about reg. expression
  2011-01-18 23:41 question about reg. expression andrew1 <andrew1@mytrashmail.com>
@ 2011-01-19 10:21 ` Samuel Gendler <sgendler@ideasculptor.com>
  2011-01-19 13:17   ` Re: question about reg. expression Stephen Belcher <sycobuny@malkier.net>
  1 sibling, 1 reply; 5+ messages in thread

From: Samuel Gendler @ 2011-01-19 10:21 UTC (permalink / raw)
  To: andrew1 <andrew1@mytrashmail.com>; +Cc: pgsql-sql

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
>

^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: question about reg. expression
  2011-01-18 23:41 question about reg. expression andrew1 <andrew1@mytrashmail.com>
  2011-01-19 10:21 ` Re: question about reg. expression Samuel Gendler <sgendler@ideasculptor.com>
@ 2011-01-19 13:17   ` Stephen Belcher <sycobuny@malkier.net>
  2011-01-19 14:18     ` Re: question about reg. expression Kenneth Marshall <ktm@rice.edu>
  0 siblings, 1 reply; 5+ messages in thread

From: Stephen Belcher @ 2011-01-19 13:17 UTC (permalink / raw)
  To: Samuel Gendler <sgendler@ideasculptor.com>; +Cc: andrew1 <andrew1@mytrashmail.com>; 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@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
>>
>
>

^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: question about reg. expression
  2011-01-18 23:41 question about reg. expression andrew1 <andrew1@mytrashmail.com>
  2011-01-19 10:21 ` Re: question about reg. expression Samuel Gendler <sgendler@ideasculptor.com>
  2011-01-19 13:17   ` Re: question about reg. expression Stephen Belcher <sycobuny@malkier.net>
@ 2011-01-19 14:18     ` Kenneth Marshall <ktm@rice.edu>
  0 siblings, 0 replies; 5+ messages in thread

From: Kenneth Marshall @ 2011-01-19 14:18 UTC (permalink / raw)
  To: Stephen Belcher <sycobuny@malkier.net>; +Cc: Samuel Gendler <sgendler@ideasculptor.com>; andrew1 <andrew1@mytrashmail.com>; pgsql-sql

On Wed, Jan 19, 2011 at 08:17:50AM -0500, Stephen Belcher wrote:
> 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
> 

That is not so. POSIX regular expressions, including the curly backet
notation, are available in all current supported releases of PostgreSQL:

http://www.postgresql.org/docs/8.2/static/functions-matching.html#FUNCTIONS-POSIX-REGEXP

I did not bother to check our local documentation for earlier releases
as to how much earlier such support was available.

Cheers,
Ken



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: question about reg. expression
  2011-01-18 23:41 question about reg. expression andrew1 <andrew1@mytrashmail.com>
@ 2011-01-22 08:59 ` Jasen Betts <jasen@xnet.co.nz>
  1 sibling, 0 replies; 5+ messages in thread

From: Jasen Betts @ 2011-01-22 08:59 UTC (permalink / raw)
  To: pgsql-sql

On 2011-01-18, andrew1 <andrew1@mytrashmail.com> wrote:
> hi all,
>
> these return t:
> select 'ab' ~ '[a-z]$'

this matches the b and the end of the string

> select 'ab' ~ '^[a-z]'

this matches the start of the string and the a

> select 'ab' ~ '^[a-z]$' returns f

> Can't I use ^ and $ at the same time to match, in this case?
> thanks.

the above expression only succeeds if the string is one character long

use '+' '*' or '{2}' etc after the '[a-z]' to allow it to match several letters

or use '^[a-z]|[a-z]$' to match any sting that starts or ends with a
letter.

what are you trying to find?

 



-- 
⚂⚃ 100% natural



^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2011-01-22 08:59 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2011-01-18 23:41 question about reg. expression andrew1 <andrew1@mytrashmail.com>
2011-01-19 10:21 ` Samuel Gendler <sgendler@ideasculptor.com>
2011-01-19 13:17   ` Stephen Belcher <sycobuny@malkier.net>
2011-01-19 14:18     ` Kenneth Marshall <ktm@rice.edu>
2011-01-22 08:59 ` Jasen Betts <jasen@xnet.co.nz>

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