marijnh / Eloquent-JavaScript

The sources for the Eloquent JavaScript book
https://eloquentjavascript.net
3.01k stars 795 forks source link

Ch. 9 – Don't need the i option on one of the Regexp Golf snippets #408

Closed mikegowen closed 6 years ago

mikegowen commented 6 years ago

In the solution for Regexp Golf, in the last snippet...

verify(/\b[^\We]+\b/i,
       ["red platypus", "wobbling nest"],
       ["earth bed", "learning ape"]);

You don't need the i option, at least for those test strings. You could make the argument that you'd want it for testing strings outside of the ones provided, but then you'd probably want to include it in the "hottentottententen" snippet as well, no?

verify(/\w{7,}/,
       ["hottentottententen"],
       ["no", "hotten totten tenten"]);
marijnh commented 6 years ago

It is supposed to check for uppercase _E_s as well. Patch 0e72735c442f4 makes this clearer.

but then you'd probably want to include it in the "hottentottententen" snippet as well, no?

No, for that regexp the i flag wouldn't change its meaning at all.