From: Michael Libby Date: 2008-11-13T21:45:06+09:00 Subject: Re: '#' characters are breaking my regexp On Thu, Nov 13, 2008 at 5:21 AM, Max Williams wrote: > I'm trying to build a regexp that includes music notes, eg Bb or C#. > However, the '#' character is breaking them - basically it just stops > reading the string as soon as it gets to a #: > >>> string = "(Ab|Bb|Db|Eb|Gb|A#|C#|D#|F#|G#|A|B|C|D|E|F|G)" > => "(Ab|Bb|Db|Eb|Gb|A#|C#|D#|F#|G#|A|B|C|D|E|F|G)" >>> regex = Regexp.new(string) > => AbBbDbEbGbA > > Can anyone explain why this is happening and how to get around it? Is > it thinking that the part after the first hash is a comment for example? The # must be confusing the parser into thinking some #{} style interpolation is going to happen. Substitute \# for # and see if that helps. Either way works the same for me in 1.8.7. -Michael Libby