Created
August 27, 2019 01:17
-
-
Save petamoriken/de40ad2601261f6cc9f746dfb90d397a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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