ruby challenge 3


This challenge is titled re, short for Regular Expression. I suppose it was good that I had been warmed up to re’s on the previous two challenges. Once again there is over a thousand lines of  mess to sort through. The hint is the candle picture, three tall candles on each side of a short one. The mess consists of random seeming upper and lower case letters. Playing around with various re’s I came up with a longish one-liner;

puts mess.scan(/[a-z][A-Z]{3}[a-z][A-Z]{3}[a-z]/).join.scan(/[A-Z][a-z][A-Z]/) "A-Z", ""

mess is the thousand plus line mess, according to the  reference at http://www.regular-expression/reference.html the {3} should have limited the [A-Z] to exactly 3 iterations, however in ruby it matched 3 or more, so I had to add the the lowercase match on each end and then strip them and the uppercase characters off one layer at a time revealing the next clue.


Looking at the other solutions I see that this could be slightly shortened;

puts mess.scan(/[a-z][A-Z]{3}([a-z])[A-Z]{3}[a-z]/).join

I didn’t realize that you could select  what you wanted out of the pattern with the inner parentheses.

Next: challenge 4; follow the chain


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s