Javascript: Capitalize all lines

Date: 2017-12-19
       function capitalizeFirstLetters(str) {
            var reEachLine = /.*?\s[^\s\.]+\.\s/gi;
            var reFirstLetter = /^[^a-z]*?([a-z])/gi;
            var match = null;
            var lines = [], line;
            var from = 0, till = 0;
            while(match = reEachLine.exec(str))
            {
                from = till;
                till = match.index + match[0].length;
                line = str.slice(from, till);
                if (line.length > 0)
                    lines.push(line);
            }

            line = str.slice(till);
            if (line.length > 0)
                lines.push(line);

            for (var i = 0; i < lines.length; i++) {
                lines[i] = lines[i].replace(reFirstLetter, function(letter) {
                        return letter.toUpperCase();
                    });
            }

            var result = lines.join('');
            if (result.length === str.length) {
                return result;
            }
            return str;
        }
9750cookie-checkJavascript: Capitalize all lines