Posted on Sunday, September 28 2014 by Ionică Bizău
Sometimes I need to parse strings as regular expressions. For example, having a string like "/hello world/gi"
, it should be converted into a real regular expression: /hello world/gi
.
For doing this, I built a Node.JS module, named regex-parser
, that parses such strings. I'm happy to announce the first stable release.
You can download it via git
or npm
:
# From GitHub, using git
$ git clone [email protected]:IonicaBizau/node-regex-parser.git node-regex-parser
$ cd node-regex-parser
$ npm install
# From NPM
$ npm install [email protected]
To convert a string into a regex you need to do:
var RegexParser = require("regex-parser");
console.log(RegexParser("/hello world/gi")); // => /hello world/gi
For full documentation and how to run tests you can visit the project GitHub page.
Have feedback on this article? Let @IonicaBizau know on Twitter.
Have any questions? Feel free to ping me on Twitter.