0

I am using this command to replace the string from PostgreSQL column:

update sentence 
set sentence_en = replace(sentence_en,"1.  ","")

but I just want to replace the first occure from left start of table column. what should I do to make it work as expect? the desire result I want when the sentence_en like this: 1. xxxxxx1. xxxx1. , the result may like this: xxxxxx1. xxxx1.

0
3

You can use the REGEXP_REPLACE() function with no additional flags.

select regexp_replace('1.  xxxxxx1.  xxxx1.  ', '1.  ', '');

returns:

xxxxxx1.  xxxx1.  

db<>fiddle here

1

regexp_replace can do this.
Use the '^' anchor character to ensure that your replacement only happens at the start of the string.

update sentence 
set sentence_en = regexp_replace('^1.  ', '', '' ); 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.