简体   繁体   English

Javascript RegExp:匹配除换行符之外的任何内容(\\ r?\\ n)

[英]Javascript RegExp: Match anything but newlines (\r?\n)

我想让我的RegExp与换行符匹配

\r?\n

This should do it: 这应该这样做:

/(?:[^\r\n]|\r(?!\n))/g

This matches either any character except \\r and \\n or a single \\r that is not followed by \\n . 这匹配除了\\r\\n之外的任何字符或者没有后跟\\n的单个\\r \\n

you can use the negative delimiter ! 你可以使用负分隔符!

so (?!(\\r|\\n)) 所以(?!(\\r|\\n))

try that 试试看

or this maybe 或者这可能

.+?(?!(\r|\n))

As an alternative suggestion why not avoid regexp? 作为另一种建议,为什么不避免regexp?

var newText = oldText.replace("\r","").replace("\n","");

This will return the string removing all the instances of \\r and \\n 这将返回删除\\r\\n所有实例的字符串

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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