Replace newline and replace <br/> with newline character.
Example: str = str.replace (/\r\n/g, "<br/>");//replace line breaks with <br/> note: \ r \ n A shortcut to a regular expression cannot be/r/n or \/r\/n
str = str.replace (/<br\/>g, "\ r \ n");//NOTE: The reserved word for the regular expression must be preceded by \ Escape
Another point:
/n or/r/n or/R may be line breaks, depends on whether your system is windows or Unix/linux or Mac
Alternatively,/s+ can be replaced under Windows, but/s+ will also match other characters, not a safe approach.
The cloud-dwelling community supplements:
In practical applications, you can not guarantee that the customer input is <br/> can also be <br> <br/> <BR> and other combinations. Then we need to use the following code to provide compatibility
Copy Code code as follows:
Dxycode=dxycode.replace (/<br\s*\/?>/gi, "\ r \ n");