From: ThoML Date: 2008-02-12T18:49:55+09:00 Subject: Re: Return number of matches > string.scan(/[^\\]\$/).size This fails on input like "$$$$", since the string will be split into "$ $", "$$". It will also not find the first $ in the string but this could be amended by using (^|[^\\]).