# Is /#$/ a Ruby bug?

**URL:** <https://www.ruby-forum.com/t/is-a-ruby-bug/51553>\
**Category:** Ruby\
**Created:** [January 3, 2006, 3:45am UTC](https://www.ruby-forum.com/t/is-a-ruby-bug/51553 "2006-01-03T03:45:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dankitania](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9a140/32.png) [@dankitania](https://www.ruby-forum.com/u/dankitania)\
**Post date:** [January 3, 2006, 3:45am UTC](https://www.ruby-forum.com/t/is-a-ruby-bug/51553/1 "2006-01-03T03:45:07Z")

</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:** ![dankitania](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9a140/32.png) [@dankitania](https://www.ruby-forum.com/u/dankitania)\
**Post date:** [January 3, 2006, 3:48am UTC](https://www.ruby-forum.com/t/is-a-ruby-bug/51553/2 "2006-01-03T03:48:08Z")

</div>

On Tue, Jan 03, 2006 at 11:42:57AM +0900, Dan K. wrote:

> 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
