Created
December 30, 2022 12:45
-
-
Save luislobo14rap/71e7127d2d95c9df530e277b62bf8e5f to your computer and use it in GitHub Desktop.
bug-regex-chrome.js
This file contains 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
// bug regex uses on chrome | |
// bug | |
const regex = /./g; | |
console.log(regex.test('a')) // true | |
console.log(regex.test('a')) // false | |
// no bug | |
const regex = /./g; | |
console.log(cloneRegex(regex).test('a')) // true | |
console.log(cloneRegex(regex).test('a')) // true | |
// clone-regex.js | |
function cloneRegex(regex) { | |
return new RegExp(regex.source, regex.flags) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment