-
Notifications
You must be signed in to change notification settings - Fork 10
Cli
Matteo Basso edited this page Dec 10, 2016
·
7 revisions
As we said before natural-regex is also available as a command line tool from npm. Using this, you can easily try your regex without running your app, so, it is an interesting tool for this reason. There are also performance reasons that we have explained here.
To install the cli, you can simply run the following:
npm install -g natural-regex-cli
Now, the cli is available in your pc and from the terminal you can run:
natural-regex --parse "starts with Lorem, then space and then foo or bar"
^(?:Lorem)\s(?:foo|bar) // this is the string that represents the regex
Here is the table of the parameters and them usage:
Option | Shortcut | Description |
---|---|---|
--help | -h | output usage information |
--version | -V | output the version number |
--parse [code] | -p | parse the given natural-regex |
--object | -o | specifies that the output will be a RegExp instead of a string |
$ natural-regex --help
Usage: natural-regex [options]
Options:
-h, --help output usage information
-V, --version output the version number
-p, --parse <code> Parse the given natural-regex
-o, --object Specify that the output will be a RegExp instead of a string
$
$ natural-regex --version
0.2.0
$
$ natural-regex --parse 'starts with Lorem, then foo or bar.'
^(?:Lorem)(?:foo|bar)
$
$ natural-regex --parse 'starts with Lorem, then foo or bar.' --object
Literal notation: /^(?:Lorem)(?:foo|bar)/
Constructor notation: new RegExp('^(?:Lorem)(?:foo|bar)')
$