繁体   English   中英

带有RegEx的string.replace()替换了错误的字符

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM