繁体   English   中英

用于查找用户在textarea中输入的文本中的换行符字符数的正则表达式(或任何其他方法)

[英]regex (or any other method) for finding the number of newline charcters in the text the user inputs in a textarea

我需要在textarea的值中计算换行符的数量(或者当用户按下返回键时插入的任何内容)。 我想我应该使用正则表达式,但我真的很糟糕,并且我不知道我应该寻找什么。

<textarea id='countIt'></textarea>

var value = $('#countIt').val();

 //need help from here

当然,如果有更聪明的方法,请随时提出建议

尝试value.split(/\\n/).length - 1

var breaksArray = value.match(/(\r\n|\n|\r)/);

暂无
暂无

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

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