Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1aoC5L-0003jn-Tc for pgus-general@arkaria.postgresql.org; Thu, 07 Apr 2016 15:43:08 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1aoC5L-0007Kz-GM for pgus-general@arkaria.postgresql.org; Thu, 07 Apr 2016 15:43:07 +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 1aoC5L-0007Kt-A0 for pgus-general@postgresql.org; Thu, 07 Apr 2016 15:43:07 +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 1aoC5H-0004UZ-Gz for pgus-general@postgresql.org; Thu, 07 Apr 2016 15:43:06 +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 C951287298; Thu, 7 Apr 2016 15:42:58 +0000 (UTC) Date: Thu, 7 Apr 2016 11:42:57 -0400 From: Greg Sabino Mullane To: "FBurgess@Radiantblue.com" Cc: "pgus-general@postgresql.org" Subject: Re: PostgreSQL POSIX regular expression problem Message-ID: <20160407154255.GD4082@localhost.localdomain> References: <3BBE635F64E28D4C899377A61DAA9FE04530581C@NBSVR-MAIL01.radiantblue.local> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-ripemd160; protocol="application/pgp-signature"; boundary="PHCdUe6m4AxPMzOu" Content-Disposition: inline In-Reply-To: <3BBE635F64E28D4C899377A61DAA9FE04530581C@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 --PHCdUe6m4AxPMzOu Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Apr 06, 2016 at 06:31:42PM +0000, FBurgess@Radiantblue.com wrote: > * Trying to build a regular expression syntax that doesn't drop the l= ast digit (5) at the very end of the phone number. >=20 > testdb=3D# select substring('OfficeName: abc office supply PhoneNumber: [= commercial] 865-999-5695 ' from 'PhoneNumber: \[commercial](.*?)(,|(\d\s+))= '); You have two parens in there - the reason you are not getting the last digi= t is that the first parens (.*?) scoops=20 up everything - including a leading space - up to the second parens (,|(\d\= s+)), which ensures that the final digit=20 plus whitespace combination is always excluded from the first match. That's a very specific regex. Can you simply slurp a phone number directly,= like so?: substring('OfficeName: abc office supply PhoneNumber: [commercial] 865-999-= 5695 ' from '([\d\-]+)') --=20 Greg Sabino Mullane greg@endpoint.com End Point Corporation PGP Key: 0x14964AC8 --PHCdUe6m4AxPMzOu Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iEYEAREDAAYFAlcGf/8ACgkQvJuQZxSWSshQgwCg3NO8MuoROVe3RponIfoTU9WZ Kg0AoJ7I1OdzQmv5anRiyLpShCOsilMs =+AsW -----END PGP SIGNATURE----- --PHCdUe6m4AxPMzOu--