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.

1 Answer 1

4

Double your backslashes. \ => \\

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

In newer PostgreSQL versions where standard_conforming_strings is on by default it is no longer necessary to double backslashes unless you're using an E'string' or have explicitly set standard_conforming_strings to off.

Sign up to request clarification or add additional context in comments.

1 Comment

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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.