Re: how to replace last 4 digital phone number into star using regexp_replace?

From: Michail Shurutov <m(dot)shurutov(at)postgrespro(dot)ru>
To: sunpeng <bluevaley(at)gmail(dot)com>, PostgreSQL general <pgsql-general(at)postgresql(dot)org>
Subject: Re: how to replace last 4 digital phone number into star using regexp_replace?
Date: 2016-08-05 10:48:44
Message-ID: 2a6ce6e9-f36a-5396-007c-cd34e0f91a9b@postgrespro.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

You should grouping first 7 digits to keep "([0-9]{7})" and
replace last 4 digits \d{4}:
postgres(at)postgres=# select
regexp_replace('18910180000,13910180000,232,abc','([0-9]{7})\d{4}',E'\\1****','g')
;
regexp_replace
---------------------------------
1891018****,1391018****,232,abc
(1 row)

Time: 73,528 ms
postgres(at)postgres=#

05.08.2016 13:35, sunpeng пишет:
> hi, friends,
> Our phone number format is 11 digital, i want to replace last 4
> digital into star, for example:
> Replace this string including 11 digital phone number:
> '18910180000,13910180000,232,abc'
> into:
> '1891018****,1391018****,232,abc'
> I try to use:
> select
> regexp_replace('18910180000,13910180000,232,abc','[0-9]{7}(\d+)','****','g')
> But it doesn't work, it will return:
> "****,****,232,abc"
> Can anyone help me? Thanks a million!
>
> Best Regards
> peng

--
WBR, Michail Shurutov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tatsuo Ishii 2016-08-05 13:06:37 Re: Uber migrated from Postgres to MySQL
Previous Message sunpeng 2016-08-05 10:35:58 how to replace last 4 digital phone number into star using regexp_replace?