Reputation: 103
I'm doing an applications in which the user is asked to write, for example, three words of a list (the order is not important).
I can try something like this:
\^ [ itemA | itemB | itemC | itemD | item E | item F] {3}
But obviously, the user can write three times the same item. Is there a way to archieve it using a regular expression and evaluate it using a single "match" function?
I'm using JavaScript, of course.
Thank you guys!
Excuse me, let me clarify.
I have the following screen:
So the user have 7 possible answers, and he have to write three of them.
Of course, this "screen" have a LOT of kind of questions in which a regex worked very well to evaluate it, but in this one, I don't know if it is enought.
Thank you guys.
Upvotes: 0
Views: 99
Reputation: 126215
To check that I've understood, you're attempting to validate that:
That's not a good fit for a regular expression. You can meet the first two requirements, but it's much simpler to do the third one directly using JavaScript or something similar.
If you really want to do it this way, you can do this:
^(itemA|itemB|itemC|itemD|item E|itemF) (?!\1)(itemA|itemB|itemC|itemD|item E|itemF) (?!\1)(?!\2)(itemA|itemB|itemC|itemD|item E|itemF)
This uses a negative lookahead:
Upvotes: 1