views:

43

answers:

1

For example I have a string that looks like the following:

var example_string = "this is the example string\n <-don't want \n\n\n";

Here I've made a string that has four newline characters in it, with three consecutive on the end. How can I programmatically have javascript tell me that there are 3 newline characters on the end?

+3  A: 
example_string.match(/\n*$/)[0].length

(\n*$ = 0 or more newlines before the end of the string, .match(...)[0] = the whole string which was matched)

jtbandes