From: Kenneth McDonald Date: 2007-08-07T12:29:58+09:00 Subject: Re: Alternate Regular Expressions? Ari Brown wrote: > I'm moderately serious. This is going to be one of those projects that > won't see the light of day for maybe 6 months to a year. > This looks largely what I was hoping to make, although in Ruby I had > invisioned this: > > matching email addresses (sample): > a = LeetExp.new(:letters => [[a-z], :insensitive], > :string => "@", > :letters => [[a-z], :insensitive], > :string => ".", > :string => ["com", "net", "org", "edu"] > ) > > case line > when a > # ... > > My idea is to make it logical and human readable. Ruby is a language > for humans and UberBeings, and I think this should reflect Ruby's ideas. Reflecting on my own experience, I'd suggest a less verbose notation, and one that uses Ruby idioms more. For example: letters = CharClass.new('a'..'z').case_insensitive a = letters + "@" + letters + "." + (Literal.new("com") | "net" | "org" | "edu") It's not at all difficult to do this with Ruby. Strings can be used for literals and character classes, and ranges are perfect for use as char ranges in character classes. Also, the ability to safely combine regular expressions (as shown above, where "letters" is used in "a") is _paramount_ in making this sort of wrapper really useful. > > Also, was you library a wrapper for underlying PERL RegExp? or was it > the whole RegExp engine? > It was in Python; instances of my 'rex' class simply construct and use Python patterns, and their associated functions, internally and invisibly to the user. Ken > Thanks, > Ari >