[英]removing \n and \r but not \r\n
我有一個包含\r
和\n
以及\r\n
的字符串。
我們如何刪除\r
和\n
,同時保持\r\n
完整?
負前瞻+后視可以做到這一點:
const test="a\nb\rc\r\nd\n\re"; console.log(test.replaceAll(/(\r(??\n)|((,<;\r)\n))/g,"x")); // ^^^^^^^^ match \r if it has no \n after // ^^^^^^^^^^^ match \n if it has no \r before
只有c
和d
之間的\r\n
保持不變。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.