How to replace newline characters and replace br with newline characters
This article mainly introduces how to replace the newline character and the br to replace the newline character, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.
Regular replacement newline character and replace with newline character
Example: str = str.replace (/\ r\ ngamma g, ""); / / replace the newline character with, note:\ r\ nShortcut for regular expression cannot use / r or\ / r\ / n
Str = str.replace (/ g, "\ r\ n"); / / Note: / reserved words for regular expressions must be preceded by\ escape
Another point is explained:
/ n or / r or / r may be newline characters, depending on whether your system is windows, Unix/Linux or mac.
In addition, / s + can also be replaced under windows, but / s + will also match other characters, which is not safe.
Add:
In practical application, you can't guarantee that what the customer input is or can be.
Wait for the combination. Then we need to use the following code to provide compatibility
Dxycode=dxycode.replace (/ / gi, "\ r\ n"); Thank you for reading this article carefully. I hope the article "how to replace newline characters and how to replace br with newline characters" shared by the editor will be helpful to you. At the same time, I hope you will support us, pay attention to the industry information channel, and more related knowledge is waiting for you to learn!