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

Negate RegExp #15

Closed
sunupf opened this issue Aug 28, 2015 · 3 comments
Closed

Negate RegExp #15

sunupf opened this issue Aug 28, 2015 · 3 comments

Comments

@sunupf
Copy link

sunupf commented Aug 28, 2015

Hi,

I trying to generate based on /^((?![0-9]).)*$/ , it shoud be valid if there is no number on the string, and I try this expression on randexp

$ node -i

var randexp = require('randexp')
new randexp(/^((?![0-9]).)*$/).gen()
';vpqBpM+eBJS2H#.W#G:q3tMdwMaU\uTJ,bhG'

but when I test the result it's return false.

/^((?![0-9]).)*$/.test(';vpqBpM+eBJS2H#.W#G:q3tMdwMaU\uTJ,bhG')
false

Thanks,

@fent
Copy link
Owner

fent commented Aug 28, 2015

I am not sure if this is an error with randexp, but I'm confused with the use of ?! with nothing preceding it, and why it would compile.

Why not use /^[^0-9]*$/?

@sunupf
Copy link
Author

sunupf commented Aug 29, 2015

actually 0-9 is just for test, i want replace it using another pattern which can be complex.

I just try too negate regexp that user inputed. that's why I use ?!

@fent
Copy link
Owner

fent commented Aug 31, 2015

Right now, randexp ignores groups that use the x(?!y) syntax. it prints a blank string for them. should it be printing something that does NOT match whatever is inside?

It's a confusing rule, /x(?!y)/.test('x') is true, as well as /x(?!y)/.test('xz'). It looks like x would be fine by itself if there is nothing after the group, otherwise it has to make sure whatever is after it also does not match the group.

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