Mr.Easy Answers McFly Mr.Easy Answers McFly - 1 year ago 104
Javascript Question

Regex for \n not working

let text= "PLEASE UPDATE WITH NEW ZSP\n- Areas with significant";

let regex = "/\n/g";

text = text.replace(regex, "<br/>")

As you can see I'm trying to convert text with a regex and it still returns the same text including

Answer Source

RegExp literals in JavaScript are objects, not strings - lose the quotes around your pattern.

let regex = /\n/g;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download