Hi Zoodor,
This one was a bit tricky. Here's the solution:
(?m)^\d+(?(?=.)(?:\s+(AND|OR)\s*))(?:\d+(?(?=.)(?:\s+\1\s*)))*$
It breaks down into 2 sections:
(?m)^\d+(?(?=.)(?:\s+(AND|OR)\s*))
First, '^' and '$' match at beginning and end of both strings and line
breaks. Second, it must begin at the beginning of a string, or a line. Match
any sequence of digits. If it is followed by any characters other than line
breaks, it must be followed by at least one space, plus one of the sequences
"AND" or "OR," followed by zero or more spaces. The result of the match
(AND|OR) is stored in Capturing Group 1.
The second section may be matched 0 or more times:
(?:\d+(?(?=.)(?:\s+\1\s*)))*$
Match any digit. If followed by anything other than a line break, it must be
followed by at least one space, plus the sequence captured in Capturing
Group 1, followed by zero or more spaces.
The result is that whichever of the "AND" or "OR" is captured is the
required match for any subsequent matching character sequences. It is only
optional for the first, as the Capturing Group is used in the second, which
is optional and may be repeated any number of times. However, the last time
it is repeated must be at the end of a line. This ensures that any line
having AND and OR in it is discarded altogether.
I tested this against the following:
1 * success
1 OR 2 * success
1 OR 2 OR 3 * success
2 AND 5 AND 6 AND 7 * success
1 AND 5 OR 6 * fail

Signature
HTH,
Kevin Spencer
Microsoft MVP
Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net
> The crux of my problem is that I want a regular expression that will match
> a
[quoted text clipped - 23 lines]
>
> Mark
Zoodor - 22 Jun 2007 16:36 GMT
Thanks Kevin, your reply was very helpful.
Mark