Ruby equivalent of assemble RE?

Is there a ruby equivalent of this?

http://search.cpan.org/dist/Regexp-Assemble/Assemble.pm

Thanks

-John

On Oct 12, 2006, at 5:47 PM, John Ky wrote:

Is there a ruby equivalent of this?

http://search.cpan.org/dist/Regexp-Assemble/Assemble.pm

I’m not aware of one, though we did play with the idea a little in a
very old Ruby Q.:

http://www.rubyquiz.com/quiz4.html

At 3,000 lines (granted a lot of that is documentation), it’s a hefty
port job. I think it’s a neat library though. Would be cool to see
it done.

James Edward G. II

James Edward G. II wrote:

At 3,000 lines (granted a lot of that is documentation), it’s a hefty
port job. I think it’s a neat library though. Would be cool to see
it done.

James Edward G. II

If what you want is a way to easily assemble and use regular
expressions, I have a Python library that comes in at about 700-800
lines (excluding unit tests and docs). For example, to define a re
matching integer complex numbers (uses the fact that Python allows
named, not just numbered, re groups):

intPat = OPT("-") + CHAR(“0123456789”)*1 # *1 means 1 or more.
complexPat = intPat[‘real’] + ALT("-", “+”)[‘op’] + intPat[‘im’]

Let’s find out the real parts of all complex numbers in a string:

for matchresult in complexPat.iter(somestring): print
matchresult[‘real’]

Using some of the package’s predefined patterns, let’s define a complex
num pattern that handles floating point numbers and whitespace:

complex = PAT.float[‘real’] + CHAR.whitespace*0 + ALT("-", “+”)[‘op’]

  • PAT.float[‘im’]

etc. etc. I’d like to convert it to Ruby, but don’t have the time. It’d
be a significant but not huge job–more tedious than anything else. I
suspect the Ruby version would come in a little shorter, maybe 600
lines? Anyone interested?

Ken

Sounds interesting, can I have a look at the source code? I may just
be interested in rewriting it in ruby.

Thanks

-John