G
Guest
The crux of my problem is that I want a regular expression that will match a
sequence of numbers that have been "ANDed" or "ORed" together in text:
e.g.
1
1 OR 2
1 OR 2 OR 3...etc.
1 AND 2
1 AND 2 AND 3...etc.
(But not 1 OR 2 AND 3, which mixes ANDs and ORs)
I tried the regular expression:
(??:[0-9]+(?: AND [0-9]+)*)|(?:[0-9]+(?: OR [0-9]+)*))
Given the string "1 OR 2" my expression will result in two matches (from a
call to Regex.Matches()), one matching "1" and another matching "2". I want
to match the whole string "1 OR 2".
Interestingly, given the string "1 AND 2", it does have the desired
behaviour (i.e. it matches the whole string as one match).
Am I doing something silly or can I not do what I want?
Any help appreciated
Mark
sequence of numbers that have been "ANDed" or "ORed" together in text:
e.g.
1
1 OR 2
1 OR 2 OR 3...etc.
1 AND 2
1 AND 2 AND 3...etc.
(But not 1 OR 2 AND 3, which mixes ANDs and ORs)
I tried the regular expression:
(??:[0-9]+(?: AND [0-9]+)*)|(?:[0-9]+(?: OR [0-9]+)*))
Given the string "1 OR 2" my expression will result in two matches (from a
call to Regex.Matches()), one matching "1" and another matching "2". I want
to match the whole string "1 OR 2".
Interestingly, given the string "1 AND 2", it does have the desired
behaviour (i.e. it matches the whole string as one match).
Am I doing something silly or can I not do what I want?
Any help appreciated
Mark