Regular Expression Question

1. Junior Member
Join Date
Dec 1969
Posts
1

## Regular Expression Question

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&#124cat&#124squirrel" <BR><BR>What&#039;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&#039;t find something that&#039;ll match "dog squirrel cat", "cat dog squirrel", etc with the same, single regular expression. <BR><BR>I&#039;m guessing it&#039;s either something really simple that I&#039;ll smack myself for missing, or just not possible to do in a single expression. (I&#039;m using the .NET Regex object.)

2. Member
Join Date
Dec 1969
Posts
48

## RE: Regular Expression Question

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&#039;m sure it&#039;s a function of the number of inputs you have (in this case, 3) but I don&#039;t think that&#039;s really necessary to figure out. In any case, here is the RegEx I came up with:<BR><BR>( (dog ( ( cat squirrel ) &#124 ( squirrel cat ) ) ) &#124 (cat ( ( dog squirrel ) &#124 ( squirrel dog ) ) ) &#124 (squirrel ( ( dog cat ) &#124 ( cat dog ) ) )<BR><BR>(As a side note, if you can&#039;t figure out a RegEx intuitively, drawing either a deterministic or nondeterministic FSM can really help and can be a good starting point.)

3. Senior Member
Join Date
Dec 1969
Posts
2,849

## RE: Regular Expression Question

Try asking this in the Regular Expression forum here, it&#039;s where all the RegExp experts hang out...<BR>http://www.aspmessageboard.com/forum/regularExpressions.asp

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•