From: Sean Middleditch Date: 2002-02-27T00:33:10+09:00 Subject: Re: Nested paired brackets in regexp Assuming that all your're doing is looking for data inside of brackets, you'd be better off using a custom search/parse engine. Basically, keep a nest value. On your first <, up the nest value by one, and mark which position in the string you found it on. Then, continue scanning the string. Up the nest value on each <, and decrease it for each >. When the next value gets back to zero, you've found the last outer value. Use the previously stored start position, and extract the data. You can then, of course, continue scanning the string, for more bracket pairs. On Tue, 2002-02-26 at 09:45, Yasuo Saito wrote: > Hi. > > Ruby's regular expression is very powerful. > > But, I cannot express paired brackets(<...>), which > might be nested, in a single regular expression. > > How can I check nested paired brackets by a single/simple > (extended) regular expression, if possible? > > eg. > input | expected > ------------------+-------------- > "abef" | "" > "abe" | "" > "abfg>h>i" | "gh>i>" > "abf" | not matched > > > Y.Saito