RegExp spec question

Виктор Мухачев addslashes at yandex.ru
Wed Jul 16 20:57:22 PDT 2014


>function* match(regex, haystack){
>  var {source, ignoreCase} = regex;
>  var newRegex = new RegExp(source, ignoreCase ? 'gi' : 'g');
>  var m = null;
>  while (m = newRegex.exec(haystack)) {
>  yield m;
>  }
>}

this code is not best in that case:

var regex = /\d+/;

var first = match(regex, "1 2 3 4");
var second = match(regex, "1 2 3 4");
first.next();
second.next(); // ?



More information about the es-discuss mailing list