From: Jason Sweat Date: 2004-11-05T11:41:07+09:00 Subject: Re: recursive brace matching with Ruby regexp On Fri, 5 Nov 2004 10:39:11 +0900, Bill Kelly wrote: > repl = [] > true while dat.gsub!(/\([^(){}]*\)|\{[^(){}]*\}/) do |str| > repl.push(str) > "\0#{repl.length - 1}\0" > end > dat.scan(/class\s+\w+\s+\0\d+\0/) do > match = $& > true while match.gsub!(/\0(\d+)\0/) { repl[$1.to_i] } > puts "Your class matched:", match > end > > The above matches arbitrarily deeply nested ( ) and { } > blocks... but all the "classes" it matches have to be > at toplevel, can't be inside a { } or ( ) themselves... > > In case it's not obvious how it works... It replaces, > from innermost to outermost, () and {} spans with a > token, and saves the original span in an array. Thanks Bill, I think I see how that works. I will play with it and see if it solves my problem. I knew there had to be a much cleaner way than what I was doing :) Regards, Jason -- http://blog.casey-sweat.us/