I want to replace something (variable → I call it "x" here) in the text (variable) with "string" + x + "string".
My code is:
new_content = content.replace(new RegExp(x,"gi"),'string'+x+'string');
So, I want to replace the uppercase and lowercase x, and x in 'string'+x+'string'should be lowercase if the search is xalso lowercase. And the same is for capital letters.
Is there a way similar $1for this situation?
source
share