X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 8AD9CD71F1 for ; Mon, 5 Sep 2005 11:15:58 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 11024-04 for ; Mon, 5 Sep 2005 14:15:50 +0000 (GMT) Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by svr1.postgresql.org (Postfix) with ESMTP id C2761D70BC for ; Mon, 5 Sep 2005 11:15:50 -0300 (ADT) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.3/8.13.3) with ESMTP id j85EFjQe033386 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 5 Sep 2005 08:15:49 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.3/8.13.3) with ESMTP id j85EFjxB050809; Mon, 5 Sep 2005 08:15:45 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.3/8.13.3/Submit) id j85EFjBJ050808; Mon, 5 Sep 2005 08:15:45 -0600 (MDT) (envelope-from mfuhr) Date: Mon, 5 Sep 2005 08:15:45 -0600 From: Michael Fuhr To: Aldor Cc: pgsql-sql@postgresql.org Subject: Re: POSIX Regular Expression question Message-ID: <20050905141545.GA20793@winnie.fuhr.org> References: <431C4EB2.80401@mediaroot.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <431C4EB2.80401@mediaroot.de> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.005 required=5 tests=[AWL=0.005] X-Spam-Level: X-Archive-Number: 200509/32 X-Sequence-Number: 22579 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