Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex match newline in textarea

I have to get the value from a textarea using jQuery and count the number of newlines there. I'd like to do this using a regex-expression. Does anyone know how to do that?

like image 845
OptimusCrime Avatar asked Sep 20 '11 06:09

OptimusCrime


1 Answers

regex does not have count. better use array like this

var val = textarea.value;
var arr = val.split(/[\n\r]/g);
var count = arr.length;

you could condense this in less rows and vars...

var count = $('textarea').val().split(/[\n\r]/g).length;
like image 152
i100 Avatar answered Sep 28 '22 16:09

i100