Re: POSIX Regular Expression question

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Aldor <an(at)mediaroot(dot)de>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: POSIX Regular Expression question
Date: 2005-09-05 14:15:45
Message-ID: 20050905141545.GA20793@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Mon, Sep 05, 2005 at 02:57:06PM +0100, Aldor wrote:
>
> I want to get out a string only with characters A-Za-z.
>
> I tried really a lot of things with substring and read many POSIX docs,
> I'm also familiar with the Perl RegEx but right now, I'm giving up... ;-(
>
> Any idea how to do this in Postgres with POSIX Regex?

Match the beginning of the string with ^.

Match one or more characters in the set A-Za-z with [A-Za-z]+ (or
with just [A-Z]+ or [a-z]+ if you're doing a case-insensitive match).
Using [[:alpha:]]+ should also work.

Match the end of the string with $.

Examples:

SELECT 'abcd' ~ '^[A-Za-z]+$';
?column?
----------
t
(1 row)

SELECT 'ABCD' ~* '^[a-z]+$';
?column?
----------
t
(1 row)

SELECT 'ABC123' ~* '^[a-z]+$';
?column?
----------
f
(1 row)

--
Michael Fuhr

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Peter Eisentraut 2005-09-05 14:19:28 Re: POSIX Regular Expression question
Previous Message A. Kretschmer 2005-09-05 14:13:02 Re: POSIX Regular Expression question