Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UKTmE-0005KA-Nw for pgsql-sql@arkaria.postgresql.org; Tue, 26 Mar 2013 13:18:58 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1UKTmE-0002gC-37 for pgsql-sql@arkaria.postgresql.org; Tue, 26 Mar 2013 13:18:58 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UKTmD-0002g6-2u for pgsql-sql@postgresql.org; Tue, 26 Mar 2013 13:18:57 +0000 Received: from proofpoint2.mail.rice.edu ([128.42.201.101] helo=pp2.rice.edu) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UKTmA-0005Er-2n for pgsql-sql@postgresql.org; Tue, 26 Mar 2013 13:18:56 +0000 Received: from pps.filterd (pp2.rice.edu [127.0.0.1]) by pp2.rice.edu (8.14.5/8.14.5) with SMTP id r2QBFlXJ026509; Tue, 26 Mar 2013 08:18:53 -0500 Received: from mh1.mail.rice.edu (mh1.mail.rice.edu [128.42.201.20]) by pp2.rice.edu with ESMTP id 1bb8v001w6-1; Tue, 26 Mar 2013 08:18:53 -0500 X-Virus-Scanned: by amavis-2.7.0 at mh1.mail.rice.edu, auth channel X-SMTP-Auth: no X-SMTP-Auth: no Received: from aart.rice.edu (aart.rice.edu [168.7.56.48]) by mh1.mail.rice.edu (Postfix) with ESMTP id C9F6A4600E7; Tue, 26 Mar 2013 08:18:52 -0500 (CDT) Received: by aart.rice.edu (Postfix, from userid 18612) id C0448100634; Tue, 26 Mar 2013 08:18:52 -0500 (CDT) Date: Tue, 26 Mar 2013 08:18:52 -0500 From: "ktm@rice.edu" To: James Sharrett Cc: pgsql-sql@postgresql.org Subject: Re: how can I replace all instances of a pattern Message-ID: <20130326131852.GF32580@aart.rice.edu> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.20 (2009-12-10) X-Proofpoint-Virus-Version: vendor=nai engine=5400 definitions=5800 signatures=585085 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 ipscore=0 suspectscore=0 phishscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=7.0.1-1111160001 definitions=main-1101130121 X-Pg-Spam-Score: -3.2 (---) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org On Tue, Mar 26, 2013 at 09:13:39AM -0400, James Sharrett wrote: > Sorry, caught a typo. Mytext1 is correctly replaced because only one > instance of the character (space) is in the string. > > This deals with the correct characters but only does the first instance of > the character so the output is: > > 'Mytext1' > 'Mytext 2' (wrong) > 'Mytext-3' (wrong) > 'My_text4' > 'My!text5' > Hi James, Try adding the g flag to the regex (for global). From the documentation: regexp_replace('foobarbaz', 'b..', 'X') fooXbaz regexp_replace('foobarbaz', 'b..', 'X', 'g') fooXX regexp_replace('foobarbaz', 'b(..)', E'X\\1Y', 'g') fooXarYXazY Regards, Ken -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql