Peña, Botp wrote:
> otoh, perl also has regex power tools like \Q..\E eg
> (escaping without using the backslash ie)
> 
> maybe we could have something similar?
> 
> =)

Interesting; I wasn't aware those worked inside the replacement string, 
as well as the regexp.

However, I'm not sure I'd want to copy Perl's ugliness here. From 'man 
perlre':

       You cannot include a literal "$" or "@" within a "\Q" sequence. 
An
       unescaped "$" or "@" interpolates the corresponding variable, 
while
       escaping will cause the literal string "\$" to be matched. 
You???ll need
       to write something like "m/\Quser\E\@\Qhost/".
...
       Beware that if you put literal backslashes (those not inside 
interpo???
       lated variables) between "\Q" and "\E", double-quotish backslash 
inter???
       polation may lead to confusing results.  If you need to use 
literal
       backslashes within "\Q...\E", consult "Gory details of parsing 
quoted
       constructs" in perlop.

That is, if you write s/'/\Q\'\E/ you'd better know what you're doing.

I think I'll live with /#{Regexp.escape("....")}/ instead :-)

B.
-- 
Posted via http://www.ruby-forum.com/.