# Is /#$/ a Ruby bug?

**URL:** <https://rubytalk.org/t/is-a-ruby-bug/23772>\
**Category:** ruby-talk\
**Created:** [3 January 2006 02:42 UTC](https://rubytalk.org/t/is-a-ruby-bug/23772 "2006-01-03T02:42:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dan\_Kohn](https://avatars.discourse-cdn.com/v4/letter/d/e99b99/32.png) [@Dan\_Kohn](https://rubytalk.org/u/Dan_Kohn)\
**Post date:** [3 January 2006 02:42 UTC](https://rubytalk.org/t/is-a-ruby-bug/23772/1 "2006-01-03T02:42:57Z")

</div>

p /#$/.match("#")[0] # syntax error: unterminated string meets eof

The interpreter seems to interpret the first # as a comment but not the  
second.

p /\#$/.match("#")[0] # this works

This seems even odder:

p /[#$]/.match("#")[0] # syntax error: compile error

p /[#\$]/.match("#")[0] # we can escape the $ rather than the #

Shouldn't the interpreter ignore # within a Regexp /.../ unless there's  
an x flag, a #{...} substitution, or a (?#...) comment? Bug or feature?

---

<div class="post-metadata">

**Author:** ![Marcel\_Molina\_Jr](https://avatars.discourse-cdn.com/v4/letter/m/edb3f5/32.png) [@Marcel\_Molina\_Jr](https://rubytalk.org/u/Marcel_Molina_Jr)\
**Post date:** [3 January 2006 02:46 UTC](https://rubytalk.org/t/is-a-ruby-bug/23772/2 "2006-01-03T02:46:00Z")

</div>

> p /#$/.match("#")[0] # syntax error: unterminated string meets eof
> 
> The interpreter seems to interpret the first # as a comment but not the  
> second.
> 
> p /\#$/.match("#")[0] # this works
> 
> This seems even odder:
> 
> p /[#$]/.match("#")[0] # syntax error: compile error
> 
> p /[#\$]/.match("#")[0] # we can escape the $ rather than the #
> 
> Shouldn't the interpreter ignore # within a Regexp /.../ unless there's  
> an x flag, a #{...} substitution, or a (?#...) comment? Bug or feature?

String interpolation with #{} need not use the enclosing curly brackets when  
interpolating instance variables or global variables:

> > $global = 'hello'

=\> "hello"

> > "the var value is #$global"

=\> "the var value is hello"

> > $/ = 'oops, gotcha'

=\> "oops, gotcha"

> > "the var value is #$/"

=\> "the var value is oops, gotcha"

marcel

> **···**
>
> On Tue, Jan 03, 2006 at 11:42:57AM +0900, Dan Kohn wrote:  
> --  
> Marcel Molina Jr. \<marcel@vernix.org\>
