var regex = /\s/
var regexGlobal = /\s/g
var str = 'foo bar baz\n\nfoo bar'
str.split(regex).length
str.match(regexGlobal).length