From: Noah Easterly Date: 2007-11-19T22:25:02+09:00 Subject: Re: Regexp for parsing? On Nov 18, 8:50 pm, Wayne Magor wrote: > I understand regular expressions, but can someone please explain this: > > re = %r/((?\((?:\\[()]|[^()]|\g)*\)))/ > > By the way, this only works with the Oniguruma engine (Ruby 1.9). > > So, now that there is the capability to match balanced parens and so > forth, does this mean that the new regular expression engine can be > used to construct simple parsers (matching language constructs)? %r/ ... / -- regexp delimter (why they didn't just use / ... /, I don't know) ( ... ) -- non-capturing group - (normally would be capturing, but see http://www.geocities.jp/kosako3/oniguruma/doc/RE.txt, part 10, case 3) -- seems rather useless, given that the only contained item is a capturing group (? ... ) -- capturing named group (see http://www.geocities.jp/kosako3/oniguruma/doc/RE.txt, part 7) \( .. \) -- literal parentheses surrounding pattern (?: ... | ... | ... )* -- non-capturing group of 3 alternatives, repeated 0 or more times \\[()] -- escaped literal parens [^()] -- anything except parens \g -- match the pg-named pattern here (recursive sub-exp - see http://www.geocities.jp/kosako3/oniguruma/doc/RE.txt, part 9)