1

I am trying to replace '</' in my code to \n </. I tried with .replace(/\<//g, '\n</') but it shows error.

2
  • Certain characters need to be escaped with a \ in regex. try .replace(/\<\//g, '\n<\/') Commented May 19, 2018 at 12:39
  • Was the answer helpful? Commented Aug 10, 2018 at 14:12

1 Answer 1

3

You need to use /<\//g. Escape the / in </ as <\/

var test = 'someTe</xt</here';
var res = test.replace(/<\//g,'\n </');
console.log(res);

Sign up to request clarification or add additional context in comments.

Comments

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.