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

Lookaheads generate content and negative lookaheads have no effect #18

Open
blixt opened this issue Sep 3, 2015 · 10 comments
Open

Lookaheads generate content and negative lookaheads have no effect #18

blixt opened this issue Sep 3, 2015 · 10 comments

Comments

@blixt
Copy link

blixt commented Sep 3, 2015

Lookaheads are only assertions that the following character(s) match, but don't actually consume characters. It seems randexp generates random content for them, however:

^(?=a).$ // can only match a single "a" but generates two characters ("a" and a random one)

Negative lookaheads should remove possible matches ahead, but randexp ignores them:

^(?!a)[a-b]$ // can only match "b" but also generates "a"
@georgePadolsey
Copy link

example of this behavior in #17

@fent
Copy link
Owner

fent commented Sep 21, 2015

Going to unify #15 and #17 into this issue.

Right now, I don't know how this would be accomplished. Specially with groups within groups and groups that come after lookaheads.

I'll have to think about it some more.

@xgbuils
Copy link

xgbuils commented Jul 18, 2016

I think that behaviour of lookahead should be the same as without using lookahead. For example: I think that randexp('x(?=y)') should produce the same kind of strings that randexp('xy') because I think that tautology rule exposed in #19 is important to be acomplished.

It is true that 'xy'.match(/x(?=y)/) === ['x']. But /x(?=y)/.test('x') is false. For that, I think that randexp('x(?=y)') should return 'xy'. Because then, /x(?=y)/.test(randexp(/x(?=y)/)) is true.

In summary I think that lookahead expressions are not useful to generate random strings. Any string produced by regular expression with lookahead can be produced with regular expression without lookaheads.

@blixt
Copy link
Author

blixt commented Jul 18, 2016

@xgbuils This issue is different than what you describe. Look again at the example:

var regex = /^(?=a).$/;
'a'.match(regex); // ["a"]
var example = randexp(regex); // "ax"
regex.test(example); // false

@xgbuils
Copy link

xgbuils commented Jul 18, 2016

But /^(?=a).$/ is very weird regular expression. I cannot understand how this regexp works because lookahead should be used after some pattern. If not, this looks like an attempt to do a lookbehind.

@esperancaJS
Copy link

I'm having the same issue with
^(?=[a-hj-npr-zA-HJ-NPR-Z0-9]{17}$)(?=.[0-9])(?=.[a-hj-npr-zA-HJ-NPR-Z])([a-hj-npr-zA-HJ-NPR-Z0-9]+)$

@JonathanMontane
Copy link

@fent any chance of having look ahead implemented in the near future? They're extremely practical when trying to do logical AND on regexes from multiple sources... (thanks for the awesome work!)

@fent
Copy link
Owner

fent commented Oct 15, 2016

I might take a shot at it eventually, but not anytime soon. :/

@WesTyler
Copy link

@PedroEsperanca what are you expecting to get back, and what are you actually getting back?

@esperancaJS
Copy link

a VIN number.

Something like:

1MEFM50293A615995

(taken from http://randomvin.com/)

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

No branches or pull requests

7 participants