I have a string like this
"test, test2, test2, test4"
i want replace after each ',' and at first char some other chars my result must show like this
“XXXtest, XXXtest2, XXXtest2, XXXtest4”
with which javascript function can i do it?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A basic regex replace should work:
We’re searching for all (
gflag) commas followed by a space (,) and replacing them with a comma, followed by a space, followed by what you want (, XXX).This won’t replace the first occurrence of
test(because the string doesn’t start with a comma), so you have to do add your replacement string to the beginning of the result.See this fiddle http://jsfiddle.net/QGURA/1/