簡體   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