Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PostgreSQL regexp_replace() to remove Brackets(Example)

I have addresses like this

420 CONSUMER SQUARE (PET SMART PARKING LOT) 

in a column and I want to remove the brackets and the word in that and the result should look like

420 CONSUMER SQUARE

How can I do this in PostgreSQL?

like image 893
Deepan Kaviarasu Avatar asked Mar 14 '16 11:03

Deepan Kaviarasu


2 Answers

Please try this

SELECT regexp_replace('420 CONSUMER SQUARE (PET SMART PARKING LOT)', '\(.*\)', '');

like image 183
Vaishali Avatar answered Nov 11 '22 21:11

Vaishali


You need to use regexp_replace function

SELECT regexp_replace('420 CONSUMER SQUARE (PET SMART PARKING LOT)', '^(.*)\\(.*?\\)', '\\1')
-- or
SELECT regexp_replace('420 CONSUMER SQUARE (PET SMART PARKING LOT)', '\\(.*?\\)$', '')

Both examples will return 420 CONSUMER SQUARE

like image 33
AlexM Avatar answered Nov 11 '22 21:11

AlexM