From: John Ky Date: 2006-10-13T14:50:59+09:00 Subject: Re: Ruby equivalent of assemble RE? Sounds interesting, can I have a look at the source code? I may just be interested in rewriting it in ruby. Thanks -John On 10/13/06, Kenneth McDonald wrote: > James Edward Gray II wrote: > 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