Issue #8714 has been updated by Eregon (Benoit Daloze).


phluid61 (Matthew Kerwin) wrote:
> That's only partly true.  # only need be escaped when it is followed by $, @ or {.  Therein lies the source of a lot of confusion.  From what I can see, ruby-doc.org says "Arbitrary Ruby expressions can be embedded into patterns with the #{...} construct." which is very easy to miss, and it's not always clear that "#$x" or /#$x/ are part of the #{...} construct.

Yeah, I wish there was only #{}, I would much rather see the removal of #@... and #$... than introducing a new literal, but I doubt it would be accepted for compatibility.


----------------------------------------
Feature #8714: Non-interpolated regular expression literal
https://bugs.ruby-lang.org/issues/8714#change-40825

Author: phluid61 (Matthew Kerwin)
Status: Open
Priority: Normal
Assignee: 
Category: core
Target version: 


=begin

I propose a new %string for non-interpolated regexp literals: %R

It is common to see erroneous bug reports around the use of ((%#%)) in regexp literals, for example where (({/[$#]/})) raises a syntax error "unexpected $undefined", and this confuses people.  The only solution is to rearrange the regular expression (such as (({/[$#]/}))), which is not always desirable.

An non-interpolated regexp, such as (({%R/[$#]/})), would allow a much simpler resolution.

=== Known Issues

* the capitalisation is the opposite of %Q(interpolated) and %q(uninterpolated)
* %R was also proposed for literal Rationals in #8430, although I believe this has been superseded by the (({1.2r})) syntax

=end



-- 
http://bugs.ruby-lang.org/