Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1aoJb3-0005zn-Qm for pgus-general@arkaria.postgresql.org; Thu, 07 Apr 2016 23:44:21 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1aoJb3-0004QO-B0 for pgus-general@arkaria.postgresql.org; Thu, 07 Apr 2016 23:44:21 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1aoJax-0004JM-B3 for pgus-general@postgresql.org; Thu, 07 Apr 2016 23:44:15 +0000 Received: from mail.endcrypt.com ([2607:f0d0:1301:23::3]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1aoJau-0006B5-1s for pgus-general@postgresql.org; Thu, 07 Apr 2016 23:44:14 +0000 Received: from localhost.localdomain (pool-108-36-163-205.phlapa.fios.verizon.net [108.36.163.205]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.endcrypt.com (Postfix) with ESMTPSA id 6D094872F6; Thu, 7 Apr 2016 23:44:08 +0000 (UTC) Date: Thu, 7 Apr 2016 19:44:06 -0400 From: Greg Sabino Mullane To: "FBurgess@Radiantblue.com" Cc: "pgus-general@postgresql.org" Subject: Re: PostgreSQL POSIX regular expression problem Message-ID: <20160407234406.GE4082@localhost.localdomain> References: <3BBE635F64E28D4C899377A61DAA9FE04530581C@NBSVR-MAIL01.radiantblue.local> <20160407154255.GD4082@localhost.localdomain> <3BBE635F64E28D4C899377A61DAA9FE045305942@NBSVR-MAIL01.radiantblue.local> <3BBE635F64E28D4C899377A61DAA9FE04530599B@NBSVR-MAIL01.radiantblue.local> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-ripemd160; protocol="application/pgp-signature"; boundary="+SfteS7bOf3dGlBC" Content-Disposition: inline In-Reply-To: <3BBE635F64E28D4C899377A61DAA9FE04530599B@NBSVR-MAIL01.radiantblue.local> X-PGP-Key: http://www.gtsm.com/Greg_Sabino_Mullane.key.html User-Agent: Mutt/1.5.24 (2015-08-30) X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgus-general Precedence: bulk Sender: pgus-general-owner@postgresql.org --+SfteS7bOf3dGlBC Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable If you want to just pull out the numbers, do a direct regexp_replace with= =20 some (\d\d\d)\D* like so: select regexp_replace('my phone: (904)-867 5309 ', '.*(\d\d\d)\D*(\d\d\d)\D= *(\d\d\d\d).*$', '\1-\2-\3'); To grab something after a specific string appears (e.g. "Corporate"), add i= t in but=20 make sure the first dot-star becomes non-greedy with a question mark: select regexp_replace('my phone: 904 867 5309 [Corporate] (703)-555-1234', '.*?Corporate.*(\d\d\d)\D*(\d\d\d)\D*(\d\d\d\d).*$', '\1-\2-\3'); --=20 Greg Sabino Mullane greg@endpoint.com End Point Corporation PGP Key: 0x14964AC8 --+SfteS7bOf3dGlBC Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iEYEAREDAAYFAlcG8MYACgkQvJuQZxSWSshZrwCgpHEoy9nV8ptJHVeJj87B5y+I 9moAnRdb/9Ly5wX/eOB4PX6l13A4RaLF =T9BR -----END PGP SIGNATURE----- --+SfteS7bOf3dGlBC--