From: Kendall Gifford Date: 2010-11-03T06:55:13+09:00 Subject: Re: Regular Expression On Tue, Nov 2, 2010 at 3:34 PM, Richard Conroy wrote: > On Tue, Nov 2, 2010 at 9:05 PM, Dv Dasari wrote: > >> I am trying to write a reqular expression to match a word with my input >> string. >> >> Input string can be ( inpstr = ABCDD ) >> >> Any suggestion on how I can fix this? >> > > You are going to need some more advanced regexes to get a match in the way > you are hoping for. > > I would get out a copy of a good regex cheat sheet, and work through some > examples in http://rubular.com > http://www.addedbytes.com/download/regular-expressions-cheat-sheet-v2/pdf/ > > The main reason for rubular is that you list all of the regexes you want to > match, and which to reject, and keep tweaking until you get what you want. > > OTOH this regex might scratch your itch: > /^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). -- Kendall Gifford zettabyte@gmail.com