Re: POSIX Regular Expression question - Mailing list pgsql-sql

From Michael Fuhr
Subject Re: POSIX Regular Expression question
Date
Msg-id 20050905141545.GA20793@winnie.fuhr.org
Whole thread Raw
In response to POSIX Regular Expression question  (Aldor <an@mediaroot.de>)
List 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


pgsql-sql by date:

Previous
From: "A. Kretschmer"
Date:
Subject: Re: POSIX Regular Expression question
Next
From: Peter Eisentraut
Date:
Subject: Re: POSIX Regular Expression question