From: "Wolfgang Nádasi-Donner" Date: 2005-07-22T18:45:57+09:00 Subject: Re: Rubys Regular Expression Engine >>>>> snip >>>>> .... Btw, can't that regular expression be simplified a bit? The two * could be turned into a single ? and the [^()] can be turned into [^(] and [^)], or? >>>>>snap >>>>> It depends on the definition of 'balanced' needed. If [^(] is used the string 'abcde(fgh' will be recognized as balanced. The two * are necessary if one needs to match balanced strings, independant of its structure, e.g. 'abvv(d(jhj)kjj)hd(jhb(j))hdjh'. This form has an advantage too. it is related to Friedl's loop enrolling structure "(*)*' and avoids endless matching. Much more complicated is the question "greedy or not greedy" in the recursion. Best regards, Wolfgang Nadasi-Donner