# Ruby equivalent of assemble RE?

**URL:** <https://www.ruby-forum.com/t/ruby-equivalent-of-assemble-re/72637>\
**Category:** Ruby\
**Created:** [October 18, 2006, 10:39am UTC](https://www.ruby-forum.com/t/ruby-equivalent-of-assemble-re/72637 "2006-10-18T10:39:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Ky](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c4cdca/32.png) [@John\_Ky](https://www.ruby-forum.com/u/John_Ky)\
**Post date:** [October 18, 2006, 10:39am UTC](https://www.ruby-forum.com/t/ruby-equivalent-of-assemble-re/72637/1 "2006-10-18T10:39:34Z")

</div>

Is there a ruby equivalent of this?

[http://search.cpan.org/dist/Regexp-Assemble/Assemble.pm](http://search.cpan.org/dist/Regexp-Assemble/Assemble.pm)

Thanks

-John

---

<div class="post-metadata">

**Author:** ![John\_Ky](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c4cdca/32.png) [@John\_Ky](https://www.ruby-forum.com/u/John_Ky)\
**Post date:** [October 18, 2006, 10:39am UTC](https://www.ruby-forum.com/t/ruby-equivalent-of-assemble-re/72637/2 "2006-10-18T10:39:47Z")

</div>

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](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](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

---

<div class="post-metadata">

**Author:** ![John\_Ky](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c4cdca/32.png) [@John\_Ky](https://www.ruby-forum.com/u/John_Ky)\
**Post date:** [October 18, 2006, 10:40am UTC](https://www.ruby-forum.com/t/ruby-equivalent-of-assemble-re/72637/3 "2006-10-18T10:40:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![John\_Ky](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c4cdca/32.png) [@John\_Ky](https://www.ruby-forum.com/u/John_Ky)\
**Post date:** [October 18, 2006, 10:40am UTC](https://www.ruby-forum.com/t/ruby-equivalent-of-assemble-re/72637/4 "2006-10-18T10:40:03Z")

</div>

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

Thanks

-John
