Last active
July 10, 2018 12:46
-
-
Save matey-jack/48fe0cf4958f425a05a79b8eb660db99 to your computer and use it in GitHub Desktop.
NodeJS v8.10.0 also backtracks on regexen: insert a space in the email address at the beginning or middle and it will be a bit slow. insert space at end and it will be very slow...
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
#!/usr/bin/node --experimental-modules | |
// fetch the dependency with: yarn add re2 | |
// I tested with [email protected] | |
import RE2 from "re2"; | |
const emailRegex = new RE2("^[A-Za-z0-9_%+-](\.?[A-Za-z0-9_%+-]+)+@[A-Za-z0-9-](\.?[A-Za-z0-9-]+)+\.[A-Za-z]{2,6}$"); | |
console.log("This is fine: " + emailRegex.test("robert.jack.frederic.manfred.otto.hermann.luis.egon.erwin@friday.de")); | |
console.log("This is false, but still fast: " + emailRegex.test("robert.jack.frederic.manfred.otto.hermann.luis.egon.erwin@friday .de")) |
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
#!/usr/bin/node | |
// this regex causes a freeze when run via TypeScript and some Webpack transpiling stuff in the browser | |
// still need to figure out why, but it's quite reassuring that NodeJS doesn't have this problem! | |
const emailRegex = /^[A-Za-z0-9_%+-](\.?[A-Za-z0-9_%+-]+)+@[A-Za-z0-9-](\.?[A-Za-z0-9-]+)+\.[A-Za-z]{2,6}$/; | |
console.log("This is fine: " + emailRegex.test("robert.jack.frederic.manfred.otto.hermann.luis.egon.erwin@friday.de")); | |
console.log("Does not match and is somewhat slow: "); | |
console.log(emailRegex.test("robert.jack.frederic.manfred.otto. [email protected]")) | |
console.log("Does not match and is really slow: "); | |
console.log(emailRegex.test("robert.jack.frederic.manfred.otto.hermann.luis.egon. [email protected]")) | |
console.log("This takes more time than my patience is long, so I don't know if it is shorter than a day or not:"); | |
console.log(emailRegex.test("robert.jack.frederic.manfred.otto.hermann.luis.egon.erwin@friday .de")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment