Re: PostgreSQL POSIX regular expression problem

From: Greg Sabino Mullane <greg(at)endpoint(dot)com>
To: "FBurgess(at)Radiantblue(dot)com" <FBurgess(at)Radiantblue(dot)com>
Cc: "pgus-general(at)postgresql(dot)org" <pgus-general(at)postgresql(dot)org>
Subject: Re: PostgreSQL POSIX regular expression problem
Date: 2016-04-07 23:44:06
Message-ID: 20160407234406.GE4082@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgus-general

If you want to just pull out the numbers, do a direct regexp_replace with
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 it in but
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');

--
Greg Sabino Mullane greg(at)endpoint(dot)com
End Point Corporation
PGP Key: 0x14964AC8

In response to

Browse pgus-general by date

  From Date Subject
Next Message t.dalpozzo@gmail.com 2016-10-14 11:22:55 journaled FS and and WAL
Previous Message FBurgess@Radiantblue.com 2016-04-07 22:15:20 Re: PostgreSQL POSIX regular expression problem