Mr.Easy Answers McFly Mr.Easy Answers McFly - 1 month ago 14
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
\n

Answer

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

let regex = /\n/g;