From: Jeff Wood Date: 2005-11-27T09:02:40+09:00 Subject: Re: String#to_rx ? How does this differ from embedding variables in regular expressions now with a = "hello world" b = "hello" c = /#{ b }/ c.match( a ).to_a #=> ["hello"] Let me know if I'm missing something... j. On 11/26/05, Nikolai Weibull wrote: > Trans wrote: > > > Could you give us a summary of how it would apply. I really don't have > > time to weed through all that material. > > There are two possible solutions as I see it that make more sense than > #to_rx: a) strings are interpreted as just that - strings of symbols > that you want to interpret literally and b) add syntax to allow you to > easily embed strings inside a regular expression. > > In Perl 6, the suggestion is to interpret $string as a string and > <$string> as a regular expression. In Ruby that'd be #{string} and > <#{string}>, I suppose. (#{regex} would still mean what it means today > in both cases.) > > Another thing that'd be nice to have is a way to insert literal strings > directly, e.g., /<'common regex operators include *, ?, and .'>/, where > <'...'> is syntax for a literal string. A way to embedd a string > variable would then perhaps be /<'#{var}'>/, but I think that the > solution in the previous paragraph may make more sense. > > I'm probably not making myself clear enough, but if what I'm saying > seems interesting I'd suggest you at least read "Synopsis 5" [1]. > > nikolai > > [1] http://www.perl.com/pub/a/2002/06/26/synopsis5.html > > -- > 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