1

I have special characters in my XML and i am using Javascript function to replace it. I have found global search to replace in all my tags as.

 var res = outputText.replace(/&/g,"&"); 

But i also want to replace </Product> tag with <btn>Click NOW</btn></Product>

How can i replace this i am trying like

res = res.replace(/</Product>/g,"<btn>Click  NOW</btn></Product>"); 

But it is giving me error invalid regular expression flag P

2 Answers 2

3

You need to escape the / with \:

res = res.replace(/<\/Product>/g,"<btn>Click  NOW</btn></Product>"); 
//------------------^
Sign up to request clarification or add additional context in comments.

Comments

1

You have to scape the / before the P

/<\/P

2 Comments

You have to have a line break so the formatting will kick in.
Thanks. It took me some try&error tests to figure it out, hehe

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.