The Dude (specialagentm) wrote in ruby_lang,
The Dude

Balanced text extraction?

This one should be simple, but I can't seem to find a clear answer via Google, and nothing in the Ruby Application Archive.

Is there something like the Perl Text::Balanced module for Ruby? That is, something that can take this:

(( some text (with a parenthetical comment)))

and extract out this:

some text (with a parenthetical comment)

I know in Perl, for some cases, you can make this work just using a "regular expression" (quoting that because I realize now that a pure RE can't handle this case -- Perl does it via extended operators and this is a known NP sort of problem for the general case). I don't believe Ruby supports these same sort of extensions?

The only mention I see of this at all (thank you Google) is this:

...but that's from 2003, so I'd think someone might have tried to figure out a way to do this by now.

I'm just trying to avoid writing my own parser for this case if I can leverage good code someone else has thought of. Any ideas?
  • Post a new comment


    default userpic