Re: regexp_replace - Mailing list pgsql-general

From Tom Lane
Subject Re: regexp_replace
Date
Msg-id 14427.1452801543@sss.pgh.pa.us
Whole thread Raw
In response to regexp_replace  (Andy Colson <andy@squeakycode.net>)
Responses Re: regexp_replace
List pgsql-general
Andy Colson <andy@squeakycode.net> writes:
> This is not doing as I'd expected:

> select regexp_replace('71.09.6.01.3', '(\d)[.-](\d)', '\1\2', 'g');

>   regexp_replace
> ----------------
>   71096.013
> (1 row)

I think regexp_replace considers only non-overlapping substrings,
eg, once it's replaced 1.0 with 10, it then picks up searching at
the 9 rather than starting over.  The dot after 6 doesn't get
removed because the 6 can't belong to two replaceable substrings, and
it already got consumed in the process of removing the dot before 6.

I might be wrong, but I think two passes of regexp_replace would
do what you want in this example.

            regards, tom lane


pgsql-general by date:

Previous
From: Andy Colson
Date:
Subject: regexp_replace
Next
From: John McKown
Date:
Subject: Re: regexp_replace