views:

133

answers:

1

I have this regex in a query in postgres and I cannot figure out why it is not matching anything after the text specified in the regex;

The idea is removing the last part, including the separator characters between.

I have records like these to match:

Villa hermosa, Pilar, PCIA. BS. AS.    
Esmeralda - Pilar - BUENOS AIRES.    
San Martin, BUENOS AIRES.-

and I'm using this expression:

 regexp_replace(location,
 '([,\s\.-]*PCIA. BS. AS[,\s\.-]*|
   [,\s\.-]*BUENOS. AIRES[,\s\.-]*$|
   [,\s\.-]*BS. AS[,\s\.-]*$|
   [,\s\.-]*P.B.A[,\s\.-]*$)', '' )

this is working fine from the text PCIA, BUENOS, but it is not taking the ',' '.' the '-' nor spaces after the word. I need help finding where the problem is.

+4  A: 

Double your backslashes. \ => \\

Postgres thinks you're doing escapes on the string itself.

SpliFF
Thank you very much! (I'm sure I tried it once, but for sure another error prevented that to work and I though it was not the cause)
Sam