[英]string.replace() with RegEx replaces wrong characters
我正在嘗試使用正則表達式(javascript)在文本中移動句點。 文字如下:
This is a text with ending period on wrong line
.
This is a another line
我用這個正則表達式:
summary.replace(/[\n\r]\.[\s\n\r]/gm, '.\r')
使它看起來像這樣:
This is a text with ending period on wrong line.
This is a another line
但它看起來像這樣:
This is a text with ending period on wrong line
.his is a another line
不知道我的正則表達式有什么問題。
任何人?
我建議您使用JSON.stringify輸出編碼為JSON的結果,以查看是否還有任何空格字符(如換行符)。 我還會為你的角色類使用量詞,以便它可以同時匹配多個角色
/[\n\r]?\.[\s\n\r]*/gm
使用此正則表達式
[\n\r]+\.(?=[\s\n\r]+)
用它替換它.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.