DEFINITIONS

Definitions More Info.
Definition ID4.058
TitlePOSTGRESQL
CategoryNOTES
Definitiontelefon telephone format degistirme, regexp word or phone format change
Definition Description-- postgresql site
https://www.postgresql.org/docs/current/functions-matching.html

--stacoverflow
https://stackoverflow.com/questions/19643232/formating-a-phone-number-in-the-postresql-query

-- yukaridaki linkte bulunan ornek sorgunun benim ornek taloda denenmesi
SELECT regexp_replace(regexp_replace(address, '\D', '', 'g'), '(\d{3})(\d{3})(\d{4})', '(\1) \2-\3') address
FROM public."PhoneFix_Cuno"
ORDER BY id DESC LIMIT 100;


-- Benim istediğim format
SELECT regexp_replace(regexp_replace(address, '\D', '', 'g'), '(\d{3})(\d{3})(\d{4})', '+90\1\2\3') address
FROM public."PhoneFix_Cuno"
WHERE createdate<'20210215'
ORDER BY id DESC
LIMIT 100;

-- BASKA ORNEk
https://www.postgresqltutorial.com/regexp_replace/

SELECT REGEXP_REPLACE('John Doe','(.*) (.*)','\2, \1');

B) String removal

Imagine you have string data with mixed alphabets and digits as follows:

ABC12345xyz
The following statement removes all alphabets e.g., A, B, C, etc from the source string:

SELECT REGEXP_REPLACE('ABC12345xyz','[[:alpha:]]','','g');

The output is:

'12345'
n this example,

[[:alpha:]] matches any alphabets
'' is the replacement string
'g' instructs the function to remove all alphabets, not just the first one.
Similarly, you can remove all digits in the source string by using the following statement:

SELECT REGEXP_REPLACE('ABC12345xyz','[[:digit:]]','','g');
Code language: JavaScript (javascript)
And the output is:

'ABCxyz'
RecordBycunay
Record Date18-02-2021 10:07:07
Düzenle
Kopyala
Sil