Skip to content

Instantly share code, notes, and snippets.

@Bacra
Last active December 20, 2015 01:49
Show Gist options
  • Save Bacra/6052174 to your computer and use it in GitHub Desktop.
Save Bacra/6052174 to your computer and use it in GitHub Desktop.
The string into a regular expression By RegExp Class
/**
* The string into a regular expression By RegExp Class
*
* @author Bacra Woo <Bacra.Woo@gmail.com>
*/
var toRegExp = function(str){
var mark;
return new RegExp(str.substring(1).replace(/\/([igm]*)$/, function(match, modifiers){
mark = modifiers;
return '';
}), mark);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment