Reputation: 2047
I use postgresql 11
I want to remove all special caracters and after that remove the first character of words which start with this characters "اآٱإأ"
this is the possibility of text :
أحمد بن حنبل
آحمد بن حنبل.
إحمد بن، حنبل
احمد بن حنبل
.أحمد. بن حنبل.
all result should be حمد بن حنبل
so remove all special characters and then remove the first character of words which start with this characters "اآٱإأ"
I find the way to remove special characters but I want in the same pattern remove also the first character of words which start with this character اآٱإأ
I try with this code :
select regexp_replace('آحمد ! بن، حنبل', '[^\w]+',' ','g')
can someone help me to find the correct query
Upvotes: 1
Views: 48
Reputation: 246523
You are already doing good! All that is missing is to remove the first character, if appropriate:
select regexp_replace(
regexp_replace('آحمد ! بن، حنبل', '[^\w]+',' ','g'),
'^[اآٱإأ]?(.*)',
'\1'
);
regexp_replace
════════════════
حمد بن حنبل
(1 row)
Note that for \w
to work as expected, the database has to be created with an Arabic locale.
Upvotes: 1