3 ms·
That call allocates a regular expression and, even ignoring that allocation, will struggle to be as fast as the count call. (On top of that, I think it’s buggy
by Someone 8y ago
That call allocates a regular expression and, even ignoring that allocation, will struggle to be as fast as the count call.
(On top of that, I think it’s buggy. It won’t count character occurrences if char is a special character such as ‘^’ or ‘.’)