Created
May 18, 2012 19:55
-
-
Save thom4parisot/2727303 to your computer and use it in GitHub Desktop.
// vs. RegExp
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
var host = 'test.om'; | |
/^.+\.[^\.]+\.om$/.exec(host); // returns 'null' | |
/* | |
* The move: | |
* 1) new RegExp(/^.+\.[^\.]+\.om$/).exec(host); | |
* 2) (new RegExp(/^.+\.[^\.]+\.om$/)).exec(host); | |
* 3) (new RegExp('^.+\.[^\.]+\.om$')).exec(host); | |
*/ | |
(new RegExp('^.+\.[^\.]+\.om$')).exec(host); // returns 'test.om' | |
//Solution: escaping dot escaper. Thanks @piouPiouM! | |
(new RegExp('^.+\\.[^\\.]+\\.om$')).exec(host); // returns 'null' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment