Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shell.js grep: internal error, Invalid regular expression #447

Closed
noteon opened this issue May 27, 2016 · 3 comments
Closed

shell.js grep: internal error, Invalid regular expression #447

noteon opened this issue May 27, 2016 · 3 comments

Comments

@noteon
Copy link

noteon commented May 27, 2016

Node version: 6.1.0

ShellJS version (the most recent version/Github branch you see the bug on): 0.7.0

Operating system: Mac OS

Description of the bug:

shell.js: internal error
SyntaxError: Invalid regular expression: /*.js/: Nothing to repeat

Example ShellJS command to reproduce the error:

shelljs.ls().grep("*.js")
@nfischer
Copy link
Member

I believe this is the expected behavior. This regex looks to be invalid. I think the regex you're looking for is grep(/.*\.js/). Note, grep()'s first argument should always be a regex, not a glob pattern to match files.

Please correct me if I've misunderstood. Cheers!

@noteon
Copy link
Author

noteon commented May 30, 2016

You can try the following example, it works. The first param is not regex, it is string. If you want to the first param is always string. you need to add some guard code.

shelljs.echo("mytest").grep("my");//result: mytest

@nfischer
Copy link
Member

The first parameter should be a regex. You can specify it either as a JS string or as a JS regex, but either way it should conform to regex syntax. This was to maintain consistent behavior. The only difference should be a matter of number of backslashes you need to escape. Hope this clarifies the confusion!

Your example is definitely correct. It should be identical in behavior to shelljs.echo("mytest").grep(/my/);, and that's the output I would expect. Hope this helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants