What is the standard way in javascript for replacing each occurrence of a certain symbol in a string with itself n times?
I have text strings where each occurrence of the single-quote symbol needs to be replaced with single-quote symbol doubled, i.e. in place of each occurrence of single-quote must appear two. This is a standard task for pre-parsing text for PostgreSQL calls.
I found out that function replace() isn't suitable for this, i.e. we cannot use it like replace('A','AA')
, it doesn't work in this special case when we have a string with repeated symbols like 'Test AA'
, which we would want to turn into 'Test AAAA'
.
So, what is the right way to do this?