Skip to content

Instantly share code, notes, and snippets.

@petamoriken
Created August 27, 2019 01:17
Show Gist options
  • Save petamoriken/de40ad2601261f6cc9f746dfb90d397a to your computer and use it in GitHub Desktop.
Save petamoriken/de40ad2601261f6cc9f746dfb90d397a to your computer and use it in GitHub Desktop.
class StatelessRegExp extends RegExp {
* exec(str, index = 0) {
let lastIndex = this.lastIndex = index;
let match;
while ((match = super.exec(str)) !== null) {
lastIndex = this.lastIndex;
yield match;
this.lastIndex = lastIndex;
}
}
* test(str, index = 0) {
let lastIndex = this.lastIndex = index;
let test;
while ((test = super.test(str)) !== null) {
lastIndex = this.lastIndex;
yield test;
this.lastIndex = lastIndex;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment