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