Issue #8714 has been updated by drbrain (Eric Hodel).


phluid61 (Matthew Kerwin) wrote:
> > %r{#$} works too.
> 
>   irb(main):004:0> %r{#$}
>   SyntaxError: (irb):4: syntax error, unexpected $undefined
>   %r{#$}
>        ^
>   	from /usr/local/bin/irb:12:in `<main>'
>   irb(main):005:0> %r{\#$}
>   => /\#$/

What ruby version are you using? It works for me. Without irb (since sometimes you can't trust it):

$ ruby -ve 'p %r{#$} =~ "foo#"'
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.4.0]
3

With irb:

$ irb
>> %r{#$} =~ "foo#"
=> 3
>> RUBY_DESCRIPTION
=> "ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.4.0]"
----------------------------------------
Feature #8714: Non-interpolated regular expression literal
https://bugs.ruby-lang.org/issues/8714#change-40803

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/