From: kasal@... (Stepan Kasal) Date: 2001-12-21T20:11:31+09:00 Subject: [ruby-talk:29213] Re: Math with RexExps (was: But is it Fun?) Hi, > Marko Schulz writes: > > Changing ... > > /^(11+)\1+$/ > > into > ... > > /^(1{2,}){2,}$/ Michael Cook wrote: > looks like you made two mistakes in that last transformation: > 1. you dropped the \1 > 2. x+ is equivalent to x{1,} not x{2,} I guess Michael's explanation doesn't follow the thoughts of Marko. I'd rather put it this way: 1) /.*/ matches "abc", right? 2) so /.{2}/ is equivalent to /../ and matches not only "xx" but also "xy" 3) on contrary, /(.)\1/ matches only "xx", not "xy" Similarily, /(1{2,}){2}/ means /(1{2,})(1{2,})/ and matches every 1-row with length >=4. The regular expression /(1{2,}){2}/ may match only strings which length is even number. Thus your example is equivalent to /^(1{2,})(1{2,})+$/ /^(1{2,})(1{2,})(1{2,})*$/ effectively /^1{4,}$/ You have to keep in mind that "{.,.}" construct, as well as "*" and "+" means repeating of the _regular expression_, not of the match. Hope this was not too detailed and boring, Stepan Kasal