![](/img/trans.png)
[英]How to match a string contain specific text preceded by any combination of alphanumerics and other charcters in regex
[英]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.