Skip to content

Instantly share code, notes, and snippets.

@luislobo14rap
Created December 30, 2022 12:45
Show Gist options
  • Save luislobo14rap/71e7127d2d95c9df530e277b62bf8e5f to your computer and use it in GitHub Desktop.
Save luislobo14rap/71e7127d2d95c9df530e277b62bf8e5f to your computer and use it in GitHub Desktop.
bug-regex-chrome.js
// 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