Received: from localhost (unknown [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id DB07E9FA18F for ; Sun, 28 Oct 2007 08:20:57 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 64786-07 for ; Sun, 28 Oct 2007 08:20:54 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from ciao.gmane.org (main.gmane.org [80.91.229.2]) by postgresql.org (Postfix) with ESMTP id 942E29FA0BA for ; Sun, 28 Oct 2007 08:20:54 -0300 (ADT) Received: from list by ciao.gmane.org with local (Exim 4.43) id 1Im6CB-0005eS-HD for pgsql-sql@postgresql.org; Sun, 28 Oct 2007 11:20:43 +0000 Received: from ppp-82-135-65-251.dynamic.mnet-online.de ([82.135.65.251]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 28 Oct 2007 11:20:43 +0000 Received: from spam_eater by ppp-82-135-65-251.dynamic.mnet-online.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 28 Oct 2007 11:20:43 +0000 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-sql@postgresql.org From: Thomas Kellerer Subject: Removing whitespace using regexp_replace Date: Sun, 28 Oct 2007 12:20:36 +0100 Lines: 34 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: ppp-82-135-65-251.dynamic.mnet-online.de User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.1.6) Gecko/20070728 Thunderbird/2.0.0.6 Mnenhy/0.7.5.666 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200710/135 X-Sequence-Number: 29507 Hi, I have a column with the datatype "text" that may contain leading whitespace (tabs, spaces newlines, ...) and I would like to remove them all (ideally leading and trailing). I tried SELECT regexp_replace(myfield, '\A\s*', '') FROM mytable; (for leading whitespace, to start with) But it does not remove anything. I replace my first attempt '^\s*' with '\A\s*' after reading the chapter about newline-sensitive matching, but that doesn't seem to do the trick either. Just for a test I changed this to SELECT regexp_replace(myfield, '\s*', '') FROM mytable; and expected *all* whitespace to be removed from my string, but only the leading ones were replaced. Which I don't understand at all. Why weren't other whitespace sequences not replaced with that expression? What would be the correct RE to replace leading and trailing whitespace without affecting anything inbetween? I'm pretty sure I'm missing someting very obvious... Thanks in advance Thomas