Skip to content

Instantly share code, notes, and snippets.

@thom4parisot
Created May 18, 2012 19:55
Show Gist options
  • Save thom4parisot/2727303 to your computer and use it in GitHub Desktop.
Save thom4parisot/2727303 to your computer and use it in GitHub Desktop.
// vs. RegExp
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