I'm trying to find the number of trailing newlines in a string. Consider the following example:
var foo = 'bar \n fooo \n \n \n';
For foo i should get back 3, meaning it won't count the newline between bar and fooo.
The way that I'm doing it right now is matching all trailing whitespaces /\s*$. and then matching /\n/g against the result to get the exact number. While this works, I was wondering if there is a way to do it with only one regular expression. Thanks for you help!
P.S.
Assume that all newlines are normalized to \n.