From: Jeff Wood Date: 2005-11-26T09:24:41+09:00 Subject: Re: String#to_rx ? ------=_Part_6809_18129292.1132964674753 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline I believe the Facets project already contains a method like this for String objects. facets.rubyforge.org j. On 11/24/05, Nikolai Weibull wrote: > > Alex Fenton wrote: > > > Possible RCR: would anyone else find this a useful addition to the > > core > > > > class String > > def to_rx > > Regexp.new( Regexp.escape(self) ) > > end > > end > > > > as a more straightforward & readable alternative to interpolation: > > > > /#{Regexp.escape(a_string)}/ > > > > I turned up a few references to this sort of thing in ruby code on the > > web. > > Please, everyone read http://www.perl.com/pub/a/2002/06/04/apo5.html and > let's use that as a base for regexes in Ruby 2. Trying to put a string > literal in a regex shouldn't be hard and Ruby should just "do the right > thing" for you. I think that regular expressions have been grossly > misused in a lot of places and a lot of ways in the applications of > computer science. I realize that we can't go back, but to be able to go > forward, perhaps we need to stop and look around - more and more > metacharacters, funky escapes, and so on isn't sustainable in the long > run. Apocalypse 5 is a good base and I think that a lot of nice things > can come out of it (well, we're here, three years later, and still > nothing, but bear with me). > > I also want a way to feed data to a regular expression for christmas, so > if you're into the whole thing of "the joy of giving", then I'm > certainly into the whole thing of "the joy of receiving". > > nikolai > > -- > Nikolai Weibull: now available free of charge at http://bitwi.se/! > Born in Chicago, IL USA; currently residing in Gothenburg, Sweden. > main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);} > > -- "Remember. Understand. Believe. Yield! -> http://ruby-lang.org" Jeff Wood ------=_Part_6809_18129292.1132964674753--