From: | "FBurgess(at)Radiantblue(dot)com" <FBurgess(at)Radiantblue(dot)com> |
---|---|
To: | "pgus-general(at)postgresql(dot)org" <pgus-general(at)postgresql(dot)org> |
Subject: | PostgreSQL POSIX regular expression problem |
Date: | 2016-04-06 18:31:42 |
Message-ID: | 3BBE635F64E28D4C899377A61DAA9FE04530581C@NBSVR-MAIL01.radiantblue.local |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | Postg토토SQL : |
* Trying to build a regular expression syntax that doesn't drop the last digit (5) at the very end of the phone number.
testdb=# select substring('OfficeName: abc office supply PhoneNumber: [commercial] 865-999-5695 ' from 'PhoneNumber: \[commercial](.*?)(,|(\d\s+))');
substring
--------------
865-999-569
(1 row)
* Removing the space at the end returns empty, but I need the complete phone number: 865-999-5695
testdb=# select substring('OfficeName: abc office supply PhoneNumber: [commercial] 865-999-5695' from 'PhoneNumber: \[commercial](.*?)(,|(\d\s+))');
substring
-----------
(1 row)
* These three examples work fine using a slight variation of the regex clause.
testdb=# select substring('OfficeName: abc office supply PhoneNumber: [commercial] 865-999-5695 abc' from 'PhoneNumber: \[commercial](.*?)(,|(\s(\w+)$))');
substring
---------------
865-999-5695
(1 row)
testdb=# select substring('OfficeName: abc office supply PhoneNumber: [commercial] 865-999-5695, abc' from 'PhoneNumber: \[commercial](.*?)(,|(\s(\w+)$))');
substring
---------------
865-999-5695
(1 row)
testdb=# select substring('OfficeName: abc office supply PhoneNumber: [commercial] 865-999-5695,' from 'PhoneNumber: \[commercial](.*?)(,|(\s(\w+)$))');
substring
---------------
865-999-5695
(1 row)
* but if I remove the last word and the comma. again I get null, when I need the phone number. The phone number may be the last value at the end of the string or it may not be.
testdb=# select substring('OfficeName: abc office supply PhoneNumber: [commercial] 865-999-5695' from 'PhoneNumber: \[commercial](.*?)(,|(\s(\w+)$))');
substring
-----------
(1 row)
thanks
Fred
From | Date | Subject | |
---|---|---|---|
Next Message | Greg Sabino Mullane | 2016-04-07 15:42:57 | Re: PostgreSQL POSIX regular expression problem |
Previous Message | FBurgess@Radiantblue.com | 2016-04-06 18:10:37 | PostgreSQL substring POSIX regular expression problem |