I\'m trying to think of a way to count the number of lines in a .csv file using Javascript, any useful tips or resources someone can direct me to?
You can use the '.' to match everything on a line except the newline at the end- it won't count quoted new lines. Use the 'm' for multiline flag, as well as 'g' for global.
function getLines(s){
return s.match(/^(.*)$/mg);
}
alert(getLines(string).length)
If you don't mind skipping empty lines it is simpler- but sometimes you need to keep them for spaceing.
function getLines(s){ return s.match(/(.+)/g); }