Regularly replace line breaks and replace <br/> with line breaks
Example: str = (/\r\n/g,"<br/>");//Replace newlines with <br/>, note: \r\n is a regular expression shortcut that cannot be used with /r/n or \/r\/n
str = (/<br\/g,"\r\n");//Note: /Reserved words for regular expressions must be escaped with \ in front
Another point of explanation:
/n or /r/n or /r may be a newline character, it depends on whether your system is Windows, Unix/Linux or Mac.
In addition, using /s+ can also be replaced in Windows, but /s+ will also match other characters, which is not a safe practice.
I add:
In practical applications, you cannot guarantee that the customer inputs a combination of <br /> or <br /> <br /> <br /> <BR>. Then we need to use the following code to provide compatibility
dxycode=(/<br\s*\/?>/gi,"\r\n");