From: Kendall Gifford Date: 2010-11-03T07:28:22+09:00 Subject: Re: Regular Expression On Tue, Nov 2, 2010 at 4:04 PM, Dv Dasari wrote: > Kendall Gifford wrote in post #958838: >> On Tue, Nov 2, 2010 at 3:34 PM, Richard Conroy >> wrote: >>> You are going to need some more advanced regexes to get a match in the way >>> /^A?B?C?D{0,2}$/ >>> >> >> The above works so long as each of ABC or D must come in said order, >> if present. This goes against the OP's examples: CA, DAD, and BAC. >> >> My suspicion is that you're problem isn't solvable by a regular >> expression alone, but that you'll need to do some parsing (still >> possibly using regular expressions in the process). > > > Yes, you are correct, this expression doesnt match words like CA or BAD > or CAD. > > Just wondering if there is an option to say all different combinations > or orders. > In theory, any language/grammar/syntax construct of finite length can be matched with a regular expression, it's just that the expression would, for most things, get really huge fast as the length of said construct grows. So, for your example you CAN match it with just ONE regular expression, but as you've noticed, it will be loooong: /^(A|B|C|D|A[BCD]|B[ACD]|C[ABD]|D[ABC]|AB[CD]|AC[BD]|AD[BCD]|BA[CD]...etc.)$/ Better to just use code in such situations, utilizing simple regex patterns in the process. -- Kendall Gifford zettabyte@gmail.com