From: Robert Klemme Date: 2008-06-18T21:20:38+09:00 Subject: Re: Regular Expressions 2008/6/18 Dave Bass : > Robert Klemme wrote: >> The easiest (but not most efficient approach) would be to create on >> alternative for each variant you have, like >> >> %r{ >> ^(?: >> v(?:\.\d+)+-\d+ >> | \w+\d+-[\d_]+ >> | ... >> )$ >> }x >> >> etc. > > The problem with regular expressions is that they can easily get out of > hand and become incomprehensible, as the above code shows (though > presumably to RK it's totally transparent). Actually the RX I presented was not complete and was intended to convey your point. :-) > Better to write a number of small regexps, each testing for a specific > pattern. Then combine the results with a logical OR. This can be done > using a flag variable, or an if-elsif tree, a case statement, etc., > whatever you feel happiest with. This approach will be a lot easier to > test and debug. Depends. If you build the one RX one alternative at a time and test during each iteration I'd say that works pretty good as well. And if the volume of data is hight the performance advantage of a single RX might pay off. Kind regards robert -- use.inject do |as, often| as.you_can - without end