Should the following lines match?
Dave Imma Dave
Dave Imma Dive Imma
I'm guessing the first one shouldn't because it doesn't contain all three names, but are duplicates okay? If not, this regex does the trick:
^(?:\b(?:(?!(?:Dave|Imma|Dive)\b)\w+[ \t]+)*(?:Dave()|Imma()|Dive())[ \t]*){3}$\1\2\3
I use the word "trick" advisedly. :) This proves that a regex can do the job, but I wouldn't expect to see this regex in any serious application. You'd be much better off writing a method for this purpose.
(By the way, if duplicates are allowed, just remove the $
.)
EDIT: Another question: should the names be matched only in the form of complete words? In other words, should these lines match?
DaveCar PomDive Imma
DaveImmaDive
So far, the only other answer that enforces both uniqueness and complete words is Coronatus's, and it fails to match lines with extra words, like these:
Dave Imma Car Pom Dive
Pyro Dave Imma Dive