From: Florian Gilcher Date: 2008-03-01T04:44:51+09:00 Subject: Re: Need a regex searching html code >> >> ab >> aabb >> aaabbb >> aaaabbbb >> etc. > > "ab > xx > aabb > aaabbb > aaabb > aaaabbbb".split.each{|s| > if s.match(/^(a+)/) and s.match(/^a+b{#{$1.size}}$/) > puts s > else > puts '-' > end > } > > Or one can use regular expression + code: > > "ab > xx > aabb > aaabbb > aaabb > aaaabbbb".split.each{|s| > if s.match(/^(a+)(b+)$/) and $1.size == $2.size > puts s > else > puts '-' > end > } > > What makes anyone think that a single regular expression > has to do all the work? > > I don't know. But many think one fits. Thats why i wrote this explanation, as it is something i see almost everyday and to give some insight to those that are pondering on why this is so. So: your solution does not fit the problem, but thanks for showing that another problem (parsing "a*nb*n" with a touring-complete language) can indeed be solved. I also stated this in my last paragraph: you can solve the problem by using regular expressions. But the language of regular expressions by itself is not mighty enough to solve it alone. Greetings Florian