簡體   English   中英

刪除 \n 和 \r 但不刪除 \r\n

[英]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

只有cd之間的\r\n保持不變。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM