From: "Eregon (Benoit Daloze)" <redmine@...>
Date: 2013-08-01T09:00:24+09:00
Subject: [ruby-core:56290] [ruby-trunk - Feature #8714] Non-interpolated regular expression literal


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


> Off the top of my head, I can't think of how to construct a regexp literal to match a hash character at the end of the string (i.e. /#$/), without first constructing a string.

Well you can escape the "#": /\#$/ =~ "#" # => 0.
%r{#$} works too.
If you want to match at the end of the String, you should use /#\z/.

But indeed simply /#$/ gives "unterminated regexp meets end of file".
After all $/ is a global variable (the input record separator), so it is only logical it interpolates it.

Also, /regexp/ literal needs escape only for # and /, and %r for # and chosen delimiter if I am not mistaken,
which is quite restricted compared to what must be escaped in "" or %Q.
----------------------------------------
Feature #8714: Non-interpolated regular expression literal
https://bugs.ruby-lang.org/issues/8714#change-40781

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/