enriquekenn
New Member
Hello, anyone who knows about this stuff... <BR><BR>I would like to do an AND search in a regular expression. <BR><BR>ie. "dog OR cat OR squirrel" equals "dog|cat|squirrel" <BR><BR>What's the AND equivalent? <BR><BR> I just cannot seem to find the equivalent for "dog AND cat AND squirrel". I can do "dog FOLLOWED BY cat FOLLOWED BY squirrel", but I just can't find something that'll match "dog squirrel cat", "cat dog squirrel", etc with the same, single regular expression. <BR><BR>I'm guessing it's either something really simple that I'll smack myself for missing, or just not possible to do in a single expression. (I'm using the .NET Regex object.)This is an ugly RegEx, but it makes sense from the correspondng finite state machine. Basically, in order to do this, a naive FSM would have 12 states. A minimized FSM still has 8 states. I'm sure it's a function of the number of inputs you have (in this case, 3) but I don't think that's really necessary to figure out. In any case, here is the RegEx I came up with:<BR><BR>( (dog ( ( cat squirrel ) | ( squirrel cat ) ) ) | (cat ( ( dog squirrel ) | ( squirrel dog ) ) ) | (squirrel ( ( dog cat ) | ( cat dog ) ) )<BR><BR>(As a side note, if you can't figure out a RegEx intuitively, drawing either a deterministic or nondeterministic FSM can really help and can be a good starting point.)Try asking this in the Regular Expression forum here, it's where all the RegExp experts hang out...<BR>http://www.aspmessageboard.com/forum/regularExpressions.asp