From: Robert Klemme Date: 2008-02-12T02:04:55+09:00 Subject: Re: Return number of matches On 11.02.2008 15:48, Christopher Causer wrote: > Jano Svitok wrote: > >> It's possible to do it in one regex, but it won't be nice and elegant >> and I don't have the time now to try it... > > I was so psyched in doing it in one regexp that I completely missed the > absolute beauty that you posted. Thanks a lot for the help. With 1.9 you can use negative lookbehind. If that's not available then it becomes ugly (if it is possible at all). The simplest pre 1.9 single pass solution that comes to mind is this irb(main):012:0> c=0 => 0 irb(main):013:0> "$\\$$".scan(/\$/) { c+=1 unless $`[-1] == ?\\ } => "$\\$$" irb(main):014:0> c => 2 Kind regards robert