isiahmeadows at gmail.com
Mon Jan 14 03:15:23 UTC 2019
If performance is an issue, regular expressions are likely to be too slow
to begin with. But you could always do this to count the number of lines in
a particular string:
var count = 0
var re = /\n|\r\n?/g
while (re.test(str)) count++
Given it's already this easy to iterate something with a regexp, I'm not
convinced it's necessary to add this property/method.
On Sat, Jan 12, 2019 at 17:29 kai zhu <kaizhu256 at gmail.com> wrote:
> a common use-case i have is counting newlines in largish (> 200kb)
> embedded-js files, like this real-world example . ultimately meant for
> line-number-preservation purposes in auto-lint/auto-prettify tasks (which
> have been getting slower due to complexity).
> would a new RegExp count-method like ```(/\n/g).count(largeCode)``` be
> significantly more efficient than existing ```largeCode.split("\n").length
> - 1``` or ```largeCode.replace((/[^\n]+/g), "").length```?
>  calculating and reproducing line-number offsets when
> linting/autofixing files
> es-discuss mailing list
> es-discuss at mozilla.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss