From: Roger Pack Date: 2009-10-06T01:49:42+09:00 Subject: Re: regex simplifier? > I tried to cook something up in the past. You can find it when > searching the archives for subject "Alternate Regular Expressions?". > HTH Very interesting thread. Did anything come of it? (or florian gross' Regexp::English looks nice [2]-- Florian?) I like this syntax (this example matches things like "-2.718 + 3.14i"): PAT.float['re'] + REP0.whitespace + ALT("+", "-")['op'] + REPO.whitespace + PAT.float['im'] + 'i' [1] I'm not sure how to do nested matches or optionals or what not however. I suppose that's the equivalent of (in 1.9) float = /[-+]?\d+\.\d+/ whitespace = /\s+/ %r{(?#{float})#{whitespace}(?[+-])#{whitespace}(?#{float})i} But the kicker is still how to remember that \s is white space, not \w. And we've been forced to do some tip toeing around the complexities of regex in order to make it readable. I had thought of a regex creator helper float = reg { optional(/[-+]/) + 'DIGIT+ \. DIGIT+' } The benefit being in not having to remember what \u or \g does, and not having to remember what /(something)?/ means :) Then you can mix it into 1.9 style regex's the same way. Thoughts? -r [1] http://aspn.activestate.com/ASPN/Mail/Message/ruby-talk/3546971 [2] http://markmail.org/message/rzudqptkuls7dncy?q=Regexp::English+gross&page=1&refer=cuj6ru2rprrvh2sm -- Posted via http://www.ruby-forum.com/.