Javascript String scan(regex)

Description

Javascript String scan(regex)


String.prototype.scan = function (regex) {
  if (!regex.global) throw "Scan Error";
  var self = this;
  var match, occurrences = [];
  while (match = regex.exec(self)) {
    match.shift();//w ww .j a  va 2s.  co  m
    occurrences.push(match[0]);
  }
  return occurrences;
};



PreviousNext

Related